filmov
tv
Pointer to Pointer (Double Pointer) in C - C Programming Tutorial 89

Показать описание
Notes for You:: Pointer to Pointer (Double Pointer) in C - C Programming Tutorial 89
- understand how to create a pointer variable; which holds address of another pointer variable.
- understand how to get or set the value at another pointer variable is pointing.
Note: a pointer to a pointer is called double pointer.
Declaring and initializing a pointer to a pointer:
Syntax:
data_type **variableName = address of another pointer variable or NULL;
Example:
int **iptr =NULL;
// iptr is a pointer variable; which can holdaddress of another integer type pointer variable
Example Code:
#include <stdio.h>
int main()
{
int a = 10;
int *iptr1 = &a;
int **iptr2 = &iptr1;
printf("Value of a=%d\n",a); // Value of a=10
printf("Address of a=%d\n",&a); // Address of a= 22 93 532
printf("\n");
printf("Value of iptr1=%d\n",iptr1);// Value of iptr1=22 93 532
printf("Address of iptr1=%d\n",&iptr1);// Address of iptr1= 22 93 528
printf("\n");
printf("Value of iptr2=%d\n",iptr2); // Value of iptr2=22 93 528
printf("Address of iptr2=%d\n",&iptr2);//Address of iptr2=22 93 524
printf("\n");
printf("Value of a=%d\n",a); // Value of a=10
printf("Value of a using iptr1=%d\n",*iptr1);//Value of a using iptr1=10
printf("Value of a using iptr2=%d\n",**iptr2); // Value of a using iptr2=10
printf("\n");
a = 20;
printf("Value of a=%d\n",a); // Value of a=20
printf("Value of a using iptr1=%d\n",*iptr1);//Value of a using iptr1=20
printf("Value of a using iptr2=%d\n",**iptr2); // Value of a using iptr2=20
printf("\n");
*iptr1 = 30;
printf("Value of a=%d\n",a); // Value of a=30
printf("Value of a using iptr1=%d\n",*iptr1);//Value of a using iptr1=30
printf("Value of a using iptr2=%d\n",**iptr2); // Value of a using iptr2=30
printf("\n");
**iptr2 = 40;
printf("Value of a=%d\n",a); // Value of a=40
printf("Value of a using iptr1=%d\n",*iptr1);//Value of a using iptr1=40
printf("Value of a using iptr2=%d\n",**iptr2); // Value of a using iptr2=40
printf("\n");
return 0;
}
Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.
=========================================
Follow the link for next video:
Follow the link for previous video:
=========================================
C Programming Tutorials Playlist:
=========================================
Watch My Other Useful Tutorials:-
Computer Programming Fundamentals Playlist:-
C Practical LAB Exercises Playlist:-
C++ Tutorials Playlist:
=========================================
► Subscribe to our YouTube channel:
► Visit our Website:
=========================================
Hash Tags:-
#ChidresTechTutorials #CProgramming #CProgrammingTutorial
- understand how to create a pointer variable; which holds address of another pointer variable.
- understand how to get or set the value at another pointer variable is pointing.
Note: a pointer to a pointer is called double pointer.
Declaring and initializing a pointer to a pointer:
Syntax:
data_type **variableName = address of another pointer variable or NULL;
Example:
int **iptr =NULL;
// iptr is a pointer variable; which can holdaddress of another integer type pointer variable
Example Code:
#include <stdio.h>
int main()
{
int a = 10;
int *iptr1 = &a;
int **iptr2 = &iptr1;
printf("Value of a=%d\n",a); // Value of a=10
printf("Address of a=%d\n",&a); // Address of a= 22 93 532
printf("\n");
printf("Value of iptr1=%d\n",iptr1);// Value of iptr1=22 93 532
printf("Address of iptr1=%d\n",&iptr1);// Address of iptr1= 22 93 528
printf("\n");
printf("Value of iptr2=%d\n",iptr2); // Value of iptr2=22 93 528
printf("Address of iptr2=%d\n",&iptr2);//Address of iptr2=22 93 524
printf("\n");
printf("Value of a=%d\n",a); // Value of a=10
printf("Value of a using iptr1=%d\n",*iptr1);//Value of a using iptr1=10
printf("Value of a using iptr2=%d\n",**iptr2); // Value of a using iptr2=10
printf("\n");
a = 20;
printf("Value of a=%d\n",a); // Value of a=20
printf("Value of a using iptr1=%d\n",*iptr1);//Value of a using iptr1=20
printf("Value of a using iptr2=%d\n",**iptr2); // Value of a using iptr2=20
printf("\n");
*iptr1 = 30;
printf("Value of a=%d\n",a); // Value of a=30
printf("Value of a using iptr1=%d\n",*iptr1);//Value of a using iptr1=30
printf("Value of a using iptr2=%d\n",**iptr2); // Value of a using iptr2=30
printf("\n");
**iptr2 = 40;
printf("Value of a=%d\n",a); // Value of a=40
printf("Value of a using iptr1=%d\n",*iptr1);//Value of a using iptr1=40
printf("Value of a using iptr2=%d\n",**iptr2); // Value of a using iptr2=40
printf("\n");
return 0;
}
Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.
=========================================
Follow the link for next video:
Follow the link for previous video:
=========================================
C Programming Tutorials Playlist:
=========================================
Watch My Other Useful Tutorials:-
Computer Programming Fundamentals Playlist:-
C Practical LAB Exercises Playlist:-
C++ Tutorials Playlist:
=========================================
► Subscribe to our YouTube channel:
► Visit our Website:
=========================================
Hash Tags:-
#ChidresTechTutorials #CProgramming #CProgrammingTutorial
Комментарии