카테고리

asm (27) bootloader_x86_grub (1) C (92) compile (11) config (76) CPP (13) CSS (1) debugging (7) gimp (1) Go (1) html (1) Java (1) JavaScript (1) kernel (19) LibreOffice (3) Linux system progamming (21) MFC (1) opencv (4) OpenGL (1) PHP (1) Python (4) qemu (29) shell (3) socket (7) troubleshooting (2) ubuntu18.04 (2) windows (1)

2018/12/14

배열 포인터 메모리 주소 자료형 변화


#include <stdio.h>

int main(void){
int c_array[4]={'o', 't', 't', 'f'};
//c_array[4] 8비트 4개 자료형 4Byte


0x2003
f


0x2002
t


0x2001
t
대표번지 0x2000 o

int d[4]={1,2,3,4};
//d[4] array 32bit 4개 자료형 32Byte


0x3012
4


0x3008
3


0x3004
2
대표번지 0x3000 1

int i;

for(i=0; i<4; ++i){
printf("memory_address of c_array[%d]=%p\n\n", i, &c_array[i]);
c_array[%d]
i
o
%p
&c_array[i]
0x2000

printf("&c_array[%d]=%p, (c_array+%d)=%p\n\n", i, &c_array[i], i, (c_array+i));
&c_array[%d]
i
t
%p
&c_array[i]
0x2001
c_array+%d
i
t
%p
c_array+i
0x2002

printf("c_array[%d]=%c_array, (c_array+%d)=%c_array\n\n", i, c_array[i],i, *(c_array+i));
&c_array[%d]
i
f
%p
&c_array[i]
0x2000
c_array+%d
i
t
%p
c_array+i
0x2001
}

for(i=0; i<4;++i){
printf("memory_address of d[%d]=%p\n\n", i, &d[i]);
memory_address of d[%d]
i
1
%p
&d[i]
0x3000

printf("&d[%d]=%p, (d+%d)=%p\n\n",i, &d[i], i, (d+i));
&d[%d]
i
2
%p
&d[i]
0x3004
(d+%d)
i
3
%p
(d+i)
0x3008

printf("d[%d]=%d, *(d+%d)=%d\n\n", i,d[i], i, *(d+1));
d[%d]
i
3
%d
d[i]
0x3008
*(d+%d)
i
4
%d
*(d+1)
0x3012
}
return 0;
}

댓글 없음:

댓글 쓰기