How to initialize Pointer Variable

Program to create, initialize and use pointer variable

/**
 * C program to create, initialize and use pointers
 */

#include <stdio.h>

int main()
{
    int num = 10;
    int * ptr;

    /* Stores the address of num to pointer type */
    ptr = &num;

    printf("Address of num = %d\n", &num);
    printf("Value of num = %d\n", num);

    printf("Address of ptr = %d\n", &ptr);
    printf("Value of ptr = %d\n", ptr);
    printf("Value pointed by ptr = %d\n", *ptr);

    return 0;
}
Output
Address of num = 6356748.
Value of num = 10
Address of ptr = 6356744
Value of ptr = 6356748
Value pointed by ptr = 10
Happy coding 😉

Comments

Popular Posts