我在堆栈溢出上读到了这个问题。
我偶然发现了int (*q)[3]; // q is a pointer to array of size of 3 integers,讨论的是理解C中的复杂声明。
我无法理解什么时候使用它,以及它是如何使用的?我该怎么解除它?有人能用一些示例代码来解释我吗,比如初始化指针和取消引用。
int main(){
int a =45;
int c[3] = {23};
int b[2][3];
int d[2][5];
int (*q)[3];
b[0][0]=1;
b[0][1]=2;
b[0][0]=3;
q = &a
char str_arr[] = "ads";
char *str_ptr = str_arr;
char **ptr_str_ptr = &str_ptr; // OK
char **ptr_str_arr = &str_arr; // compile error: cannot initialize a variable of type 'char**' with a rvalue of type 'char*[4]'
我搞不懂为什么我们不能得到str_arr的地址。有什么想法吗?
给定ADDR_X的内存地址,其中我有一些值的专用hw寄存器,地址类型转换会违反严格的混叠吗?
//lets use some arbitrary address for the sake of this example
#define ADDR_X 0xE0F0
void function(void)
{
some_structure_type *my_struct_ptr = (some_structure_type *)ADDR_X;
my_struct_ptr->a_field = 1;
...
}
是否存在指向some_structure_type指
int main(){
int a[4] = { 1,2,3,4 };
int(*b)[4] = &a; //with a doesn't work
cout << a << &a << endl; //the same address is displayed
}
因此,int(*b)[4]是指向ints数组的指针。我尝试用&a和a来初始化它。它只适用于第一个。
它们都不是数组第一个元素的地址吗?
void*可以分配给任何指针变量,也可以从指针变量中分配,这是C的一个熟悉的特性。在N1570 ( C11的标准文档草案)中,这是在6.3.2.3 Pointers中指定的
指向空的指针可以转换为指向任何对象类型的指针,也可以从指向任何对象类型的指针转换。指向任何对象类型的指针可以再次转换为无效指针和返回指针;结果应与原始指针相比较。
但是6.2.7 Compatible type and composite type说
引用同一个对象或函数的所有声明都应该具有兼容的类型;否则,行为就没有定义。
然而,据我所见,该部分并没有说void*与其他指针类型兼容。所以:
int x =
我想创建一个函数来释放指针所指向的内存,并将该指针赋值为NULL。因此,我必须将参数声明为void** (间接指针),我知道void*对于转换指针是安全的,并且使用void**是未定义的行为。但我认为在这个situation.Will中应该没有问题,这个函数安全地释放malloc()分配的任何内存,而不会有未定义的行为?请黑客帮助或提出更好的方法。 C代码: #include <stdio.h>
#include <stdlib.h>
// If I use safeFree(&mac_arr); ,
// it will warn "Incompa
我试图编写一个返回数据数组起始地址的函数。
// Return starting address of the data array
data_t *get_vec_start(vec_ptr v)
{
data_t *address = v->data[0];
return address;
}
我收到一个错误,上面写着:
vec.c: In function ‘get_vec_start’:
vec.c:75:20: error: incompatible types when initializing type ‘da
当我运行pub get时,会遇到以下错误:
The plugin geocoder uses a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove the
我试图使用NDK在Android中编写本机C代码。我有一个函数segment_offline(),它接受许多参数,包括整数指针int * num_segments。我想要这个指针,因为我想读取分配给这个指针所指向的整数的值,该值位于我的C函数中,充当我的JNI接口。以下是segment_offline()的代码
int * segment_offline(const SEGMENT_DATATYPE *x, const int num_samples_x, const float *svara_cents, const int *svara_lengths, const int num_sva