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

Last Updated: February 24, 2019 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

Top Related Articles:

  1. C Program to Convert time from 24 hour to 12 hour format
  2. C Program to Check whether an Alphabet is Vowel or Consonant
  3. C Program to print current date and time
  4. C Program to concatenate two strings without using strcat
  5. C Program to print date of birth using structure

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

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

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap