1 /************************************************************************* 2 > File Name: ptr_variable.c 3 > Author: Mr.Yang 4 > Purpose:演示指向變量的指針 5 > Created Time: 2017年06月03日 星期六 08時47分33秒 6 ************************************************************************/ 7 8 #include <stdio.h> 9 #include <stdlib.h> 10 11 int main(void) 12 { 13 int a = 1000; 14 printf("a的地址為:%d\n",&a); 15 16 int *p; 17 *p = 5; 18 printf("指針p的地址為:%d\n"&p); 19 20 return 0; 21 }
錯誤描述如下:
1 ptr_variable.c: In function ‘main’: 2 ptr_variable.c:18:37: error: invalid operands to binary & (have ‘char *’ and ‘int *’) 3 printf("指針p的地址為:%d\n"&p);
說明:錯誤出現在main函數,第18行,錯誤類型二進制操作數無效,printf函數中char *和int *並列了,錯誤的代碼為printf("指針p的地址為:%d\n"&p);仔細查看,可知道中間少了一個逗號。
