我得到了我想要的输出,但不知道如何摆脱这些警告。任何帮助表示赞赏。
警告:
Format 指定类型 'void *' 但参数类型为 'char' [-Wformat] printf("\n指针变量的值为 %p\n", *myString);
"Format 指定类型 'void *' 但参数的类型为 'char' [-Wformat] printf("%p\n", myString[x]);
#include <stdio.h> #include <stdlib.h> int main() { char *myString = "Daniel"; int x; printf("\nThe pointer variable's value is %p\n", *myString); printf("\nThe pointer variable points to %s\n", myString); printf("\nThe memory location for each character are: \n"); for (x = 0;x < 7;x++){ printf("%p\n", myString[x]); } return 0; }
输出:
The pointer variable's value is 0x44
The pointer variable points to Daniel
The memory location for each character are:
0x44
0x61
0x6e
0x69
0x65
0x6c
(nil)