Write a C Program to create, initialize and access a pointer variable

Write a C Program to create, initialize and access a pointer variable


 #include <stdio.h>
 int main()
 {
	//char variable
    char ch;

    //char pointer
    char *pCh;



    /* Initializing pointer variable with the
     * address of variable ch
     */
    pCh = &ch;

    //Assigning value to the variable ch
    ch = 'A';

    //access value and address of ch using variable ch
    printf("Value of ch: %c\n",ch);
    printf("Address of ch: %p\n",&ch);



    //access value and address of ch using pointer variable pCh
    printf("Value of ch: %c\n",*pCh);
    printf("Address of ch: %p",pCh);

   return 0;
 }
          

Output:

 Value of ch: A
 Address of ch: 000000000022FE47
 Value of ch: A
 Address of ch: 000000000022FE47
 --------------------------------