Q:

C program to create, initialize, assign and access a pointer variable

belongs to collection: C pointers example programs

0

C program to create, initialize, assign and access a pointer variable

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to demonstrate example of array of point... >>
<< C program to swap two numbers using pointers...