>  기사  >  백엔드 개발  >  C 언어의 이중 포인터(포인터 대 포인터)

C 언어의 이중 포인터(포인터 대 포인터)

WBOY
WBOY앞으로
2023-09-10 12:09:03536검색

C 언어의 이중 포인터(포인터 대 포인터)

포인터는 변수의 주소를 저장하는 데 사용됩니다. 따라서 포인터에 대한 포인터를 정의할 때 첫 번째 포인터는 두 번째 포인터의 주소를 저장하는 데 사용됩니다. 그래서 이중 포인터라고 부른다.

Algorithm

Begin
   Declare v of the integer datatype.
      Initialize v = 76.
   Declare a pointer p1 of the integer datatype.
   Declare another double pointer p2 of the integer datatype.
   Initialize p1 as the pointer to variable v.
   Initialize p2 as the pointer to variable p1.
   Print “Value of v”.
      Print the value of variable v.
   Print “Value of v using single pointer”.
      Print the value of pointer p1.
   Print “Value of v using double pointer”.
      Print the value of double pointer p2.
End.

이중 포인터를 이해하는 간단한 프로그램:

Example

int main() {
   int v = 76;
   int *p1;
   int **p2;
   p1 = &v;
   p2 = &p1;
   printf("Value of v = %d\n", v);
   printf("Value of v using single pointer = %d\n", *p1 );
   printf("Value of v using double pointer = %d\n", **p2);
   return 0;
}

Output

Value of v = 76
Value of v using single pointer = 76
Value of v using double pointer = 76

위 내용은 C 언어의 이중 포인터(포인터 대 포인터)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제