Ex05-변수의 시작주소 출력하기

CODEDRAGON Development/C, C++

반응형

변수의 시작주소 출력하기

  • &: 주소연산자, 변수의 시작주소를 출력
  • 주소값은 16진수로 찍는다.

   

   

스택 메모리 구조

지역변수는 스택이라는 메모리공간에 차곡차곡 쌓이게 됩니다.

   

   

소스코드

   

  1. #include <stdio.h>
  2. int main(void){
  3.         int a=3;
  4.         int b=7;
  5.         int c=10;
  6.         printf("a : %d \n", a);
  7.         printf("b : %d \n", b);
  8.         printf("c : %d \n", c);
  9.         printf("변수 a 시작 주소 : %x \n", &a);
  10.         printf("변수 b 시작 주소 : %x \n", &b);
  11.         printf("변수 c 시작 주소 : %x \n", &c);
  12.         printf("\n");
  13.         //메모리값을 통해 메모리 순서형태대로 찍어보기 (지역변수가 메모리에 쌓이는 순서)
  14.         printf("변수 c 시작 주소 : %x \n", &c);
  15.         printf("변수 b 시작 주소 : %x \n", &b);
  16.         printf("변수 a 시작 주소 : %x \n", &a);
  17.         printf("\n");
  18.         //메모리값 10진수로 찍어보기
  19.         printf("변수 c 시작 주소(10진수) : %d \n", &c);
  20.         printf("변수 b 시작 주소(10진수) : %d \n", &b);
  21.         printf("변수 a 시작 주소(10진수) : %d \n", &a);
  22.         printf("\n");
  23.         //메모리값 8진수로 찍어보기
  24.         printf("변수 c 시작 주소(8진수) : %o \n", &c);
  25.         printf("변수 b 시작 주소(8진수) : %o \n", &b);
  26.         printf("변수 a 시작 주소(8진수) : %o \n", &a);
  27.         return 0;
  28. }

 


 

   

출력결과

   

   

   

   

반응형