Tag: 指针

在’ – >’标记之前预期的unqualified-id,如何解决这个问题?

struct box { char word[200][200]; char meaning[200][200]; int count; }; struct root { box *alphabets[26]; }; struct root *stem; struct box *access; void init(){ int sizeofBox = sizeof(struct box); for(int i = 0 ; icount = 0; root->alphabets[i] = temp; //error line } } 错误:在’ – >’标记之前预期的unqualified-id 如何解决这个bug。 谁能解释一下这是什么类型的?

C中的void函数如何与指针一起使用?

我试图在C编程中创建一个与指针一起使用的void函数。 我创建了以下与指针一起使用的函数: #include int function_1(int *num1, int *num2) { int *total; *total = *num1 / *num2; return *total; } int main(void) { int numerator; int denominator; int finalAnswer; printf(“Numerator: “); scanf(“%d”, &numerator); printf(“Denominator: “); scanf(“%d”, &denominator); finalAnswer = numerator / denominator; printf(“%d / %d = %d \n”, numerator,denominator,finalAnswer); } 这个程序没有问题,但是当我改变后的第一行时 #include 对此: void function_1(int *num1, […]

为什么calloc指针类型是void *?

我读了一本C书。 但是不能理解那句话 如果调用calloc成功,则返回指向内存中数组基类的void *类型的指针; 这里,如果指向类型为void *的指针指向内存中数组的基数,那么array [0]的类型为void? 我想知道什么意思…… 谢谢大家阅读我的问题,希望得到答复!

在C中,无符号和有符号字符指针之间的转换何时变得不安全?

如果我在clang和Visual Studio中都这样做: unsigned char *a = 0; char * b = 0; char x = ‘3’; a = & x; b = (unsigned char*) a; 我收到警告,我正在尝试在有符号和无符号字符指针之间进行转换,但代码确实有效。 虽然编译器说这是有原因的。 你能指出一个可能变成问题的情况吗?

int数组的未知大小

我有一个包含int数组的struct 。 我不想修复数组的大小,因为我不知道有多少元素会进入它并且不想浪费内存。 一个int指针数组本质上是相同的。 我尝试了一个指向整数数组的指针和一个无效的双指针。 我怎么能做到这一点? 注意: 我的意思是int指针数组是如果我设置一个固定大小的int指针数组,那么我仍然在浪费空间,所以在这个意义上它与int的固定大小数组没有区别。 唯一的区别是int和int pointer大小可能不同。

当int指针被类型化为char时会发生什么?

int main(){ int a; char *x; x = (char *) &a; a=512; x[0]=1; x[1]=2; printf(“%d\n”,a); return 0; } 这段代码的输出是513.你能解释一下吗?

指针作为参数为null但是在函数指针不为null之后

你好,我有我的function: void enterString(char *string) { string = (char*)malloc(15); printf(“Enter string: “); scanf(“%s”,string); //don’t care about length of string now } int main() { char *my_string = NULL; enterString(my_string); printf(“My string: %s\n”,my_string); /* it’s null but i want it to show string i typed from enterString */ return 0; } 我想从主要的字符串函数show中串起来…我不知道你是否理解我。 谢谢 :)

将单指针和双指针传递给c 中的函数

我试图在函数中传递单个指针和双指针 。 但它给了我错误。 int main() { int *pt; fun(pt); . . } fun(int *pt) { pt=(int*)malloc(6*sizeof(int)); . . } 我们使用双指针时的语法是什么。 任何人都可以用一个例子来描述它,或者可以编辑上面的例子。 我将非常感谢你。

使用free()释放内存不起作用

这是一个小程序,它填充一些数组并在屏幕上打印其内容: #include #include typedef struct{ double **plist; int plistSize; } ParticleList; void sendPar(int *n, int np){ // allocate memory for struct pl ParticleList pl; // allocate memory for ParticleList np times pl.plist = malloc(sizeof(ParticleList) * np); // allocate memory for lists of size n[k] for(int k=0; k<np; k++){ pl.plist[k] = malloc(sizeof(double) * n[k]); } // […]

检查指针是否在malloc’d区域?

我正在制作一个动态内存分配器,我需要检查,而不是当我释放它的一部分时,我传入函数的指针实际上是在该区域内。 我有一个指向malloc’d区域开头的指针 typedef unsigned char byte; static byte *memory // pointer to start of allocator memory 我在启动函数中分配的。 我也存储了malloc’d区域的大小 static u_int33_t memory_size; // number of bytes malloc’d in memory[] 我如何确保ptr不…(伪代码) ptr *memory + memory_size 并且该代码导致以下错误; 错误:不同指针类型的比较缺少强制转换[-Werror] if(object (memory + memory_size))^ 我不确定我需要投出什么以及什么不… 免费function如下…… void memfree(void *object) { if ( object (memory + memory_size)) { fprintf(stderr, “vlad_free: Attempt […]