Code&Data Insights

[C++ Programming] Pointer 본문

Computer Science/Comp sci_courses

[C++ Programming] Pointer

paka_corn 2022. 8. 17. 03:35

 

 

 

 < C++ - Pointer >

What is Pointer? 

=> A pointer is a variable whose value is the address of another variable. Like any variable or constant, you must declare a pointer before you can work with it. The general form of a pointer variable declaration is −

( 포인터란 다른 변수의 주소를 가진 변수이다. 다른 변수나 상수와 같이, 반드시 포인터를 사용하기 전에 선언되어야 한다. )

type *var-name;

 

* the pointer's base type

int *ip; // pointer to an integer
double *dp; // pointer to a double
float *fp; // pointer to a float
char *ch // pointer to character

 

 

 

 

포인터의 메모리 해제 (  delete 연산자 )

=> 프로그램의 다른 부분이 포인터에 할당된 메모리를 사용할 수 있도록 반환해주는 것 

(new 연산자로 포인터를 사용한 뒤에는 반드시 delete를 사용해야 한다.) 

 

- new[]로 메모리를 대입 할 경우, delete[]로 메모리를 해제해야 함. 

Comments