| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <stdio.h> int main(void) { int n = 7; printf("n: %d ", n); printf("&n: %x ", &n); // Wrong printf("&n: %lx ", &n); // This is the right one printf("포인터 하나당 크기는 %ld 바이트", sizeof(void *)); printf("&n: %p ", &n); return 0; } |
디씨 사정상 ' '은 짤림
beriss@beriss-pc:~/debug/test$ gcc test.c test.c: In function ‘main’: test.c:16:18: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int *’ [-Wformat=] printf("&n: %x ", &n); // Wrong ~^ ~~ %ls test.c:18:19: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘int *’ [-Wformat=] printf("&n: %lx ", &n); // This is the right one ~~^ ~~ %ls beriss@beriss-pc:~/debug/test$ ./a.out n: 7 &n: 865a54 (0x00865a54) &n: 7ffd00865a54 (0x00007ffd00865a54) 포인터 하나당 크기는 8 바이트 &n: 0x7ffd00865a54
이건 알겠는데 저 밑에 글 보고 다시 글써볼게