BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C program to create, initialize and access a pointer variable

By Chaitanya Singh | Filed Under: C Programs

In this tutorial, we will write a C program to create, initialize and access a pointer variable. To learn the basics of pointer refer my tutorial: C Pointers

Example: Program to create, access and initialize a Pointer

In the following program we have declared a character variable ch and character pointer pCh, later we initialized the pointer variable pCh with the address value of char ch.
The example also shows how to access the value and address of ch using the pointer variable pCh

/* Created by Chaitanya for Beginnersbook.com
 * C program to create, initialize and access a pointer
 */

#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:
C program to create, initialize and access a pointer variable

Related C Examples

1. C program to check leap year
2. C program to swap two numbers
3. C program to find the size of int, float, double and char
4. C program to find ASCII value of a character

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Programs

  • C Programs
  • Java Programs
  • C++ Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap