>  기사  >  백엔드 개발  >  포인터 사이의 관계를 보여주는 C 프로그램

포인터 사이의 관계를 보여주는 C 프로그램

PHPz
PHPz앞으로
2023-09-08 23:45:021399검색

포인터 사이의 관계를 보여주는 C 프로그램

C 프로그래밍 언어에서 포인터 또는 이중 포인터에 대한 포인터는 다른 포인터의 주소를 보유하는 변수입니다.

선언

아래에는 포인터에 대한 포인터 선언이 나와 있습니다.

datatype ** pointer_name;

예: int **p

여기서 p는 포인터에 대한 포인터입니다.

초기화

'&'는 초기화에 사용됩니다.

예를 들어

int a = 10;
int *p;
int **q;
p = &a;

Access

간접 연산자(*)를 사용하여 액세스합니다.

예제 프로그램

다음은 이중 포인터용 C 프로그램입니다. -

라이브 데모
#include<stdio.h>
main ( ){
   int a = 10;
   int *p;
   int **q;
   p = &a;
   q = &p;
   printf("a =%d ",a);
   printf(" a value through pointer = %d", *p);
   printf(" a value through pointer to pointer = %d", **q);
}

Output

위 프로그램이 실행될 때 실행되면 다음과 같은 결과가 생성됩니다. -

a=10
a value through pointer = 10
a value through pointer to pointer = 10

Example

이제 포인터 대 포인터 관계를 보여주는 또 다른 C 프로그램을 고려해보세요.

라이브 데모

#include<stdio.h>
void main(){
   //Declaring variables and pointers//
   int a=10;
   int *p;
   p=&a;
   int **q;
   q=&p;
   //Printing required O/p//
   printf("Value of a is %d</p><p>",a);//10//
   printf("Address location of a is %d</p><p>",p);//address of a//
   printf("Value of p which is address location of a is %d</p><p>",*p);//10//
   printf("Address location of p is %d</p><p>",q);//address of p//
   printf("Value at address location q(which is address location of p) is %d</p><p>",*q);//address of a//
   printf("Value at address location p(which is address location of a) is %d</p><p>",**q);//10//
}

Output

위 프로그램이 실행되면 다음과 같은 결과가 나옵니다 -

Value of a is 10
Address location of a is 6422036
Value of p which is address location of a is 10
Address location of p is 6422024
Value at address location q(which is address location of p) is 6422036
Value at address location p(which is address location of a) is 10

위 내용은 포인터 사이의 관계를 보여주는 C 프로그램의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

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