Home » C solved 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?



/*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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.