C Program to Create Initialize and Access a Pointer Variable

Write a c program to create, initialize, and access a pointer variable with an example. In this example, we declared an integer value, assigned it to the pointer of int type, and printed that pointer value and address.

#include <stdio.h>

int main()
{   
    int num;
    int *pnum;
    
    pnum = &num;
    num = 200;

    printf("Information of the Normal num Variable\n");
    printf("num = %d Address of num = %u\n", num, &num);

    printf("Information of the Pointer pnum Variable\n");
    printf("num = %d Address of num = %u\n", *pnum, pnum);

}
C Program to Create Initialize and Access a Pointer Variable

This c program created a char variable, initialized with a random character, and accessed or printed that character pointer.

#include <stdio.h>

int main()
{   
    char ch;
    char *pch;

    pch = &ch;

    printf("Please Enter Any Charcater = ");
    scanf("%c", &ch);

    printf("Information of the ch Variable\n");
    printf("num = %c Address of num = %p\n", ch, &ch);

    printf("Information of the Pointer pch Variable\n");
    printf("num = %c Address of num = %p\n", *pch, pch);

}
Please Enter Any Charcater = o
Information of the ch Variable
num = o Address of num = 0x7ff7b26716af
Information of the Pointer pch Variable
num = o Address of num = 0x7ff7b26716af

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.