gcc編譯出現:error: invalid operands to binary & (have ‘char *’ and ‘int *’)


 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);仔細查看,可知道中間少了一個逗號。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM