Home »
C programs »
C pointer programs
C program to create, initialize, assign and access a pointer variable
In this C program, we are going to learn how to declare, initialize a pointer? How to assign and access value through the pointer?
Program
/*C program to create, initialize, assign and access a pointer variable.*/
#include <stdio.h>
int main()
{
int num; /*declaration of integer variable*/
int *pNum; /*declaration of integer pointer*/
pNum=& num; /*assigning address of num*/
num=100; /*assigning 100 to variable num*/
//access value and address using variable num
printf("Using variable num:\n");
printf("value of num: %d\naddress of num: %u\n",num,&num);
//access value and address using pointer variable num
printf("Using pointer variable:\n");
printf("value of num: %d\naddress of num: %u\n",*pNum,pNum);
return 0;
}
Output
Using variable num:
value of num: 100
address of num: 2764564284
Using pointer variable:
value of num: 100
address of num: 2764564284
C Pointer Programs »