728x90
C언어에서 포인트작업 예시.
예시1.
#include <stdio.h>
int main()
{
int var = 5;
printf("Value: %d\n", var);
printf("Address: %u", &var); //Notice, the ampersand(&) before var.
return 0;
}
출력
Value: 5
Address: 2686778
예시2.
변수의 주소를 추출하려면 참조연산자 사용한다 - & - 참조연산자
포인트 변수를 역참조 할때 사용하는 연산자 - * -
배열 이름은 포인터이다. 배열이름은 포인터 상수라 할 수 있다.
/* Source code to demonstrate, handling of pointers in C program */#include <stdio.h>
int main(){
int* pc;
int c;
c=22;
printf("Address of c:%u\n",&c);
printf("Value of c:%d\n\n",c);
pc=&c;
printf("Address of pointer pc:%u\n",pc);
printf("Content of pointer pc:%d\n\n",*pc);
c=11;
printf("Address of pointer pc:%u\n",pc);
printf("Content of pointer pc:%d\n\n",*pc);
*pc=2;
printf("Address of c:%u\n",&c);
printf("Value of c:%d\n\n",c);
return 0;
}
728x90
'Web Site Note' 카테고리의 다른 글
Material CSS (0) | 2017.12.13 |
---|---|
javascript basic (0) | 2017.12.13 |
C언어프로그래밍 (0) | 2017.05.08 |
비주얼베이직프로그램 (0) | 2017.05.04 |
비주얼베이직 6.0 기초 (0) | 2017.05.04 |