Character pointer
All concepts are similar to the integer pointer. If you are directly reading this article, kindly go through the integer pointer topic before getting started with this.
A character pointer only stores an address of a character variable.
Syntax
char *ptr;
Animated Tutorial
Referencing and dereferencing of a character pointer
Example
#include<stdio.h> int main() { char var = 'a',*ptr; ptr = &var; //ptr references var printf("Address of var = %x\n",&var); printf("ptr is pointing to an address %x\n",ptr); /* use '*' operator to access the value stored at ptr, i.e. dereferencing ptr */ printf("Value stored at ptr = %c",*ptr); return 0; }
Output
For the sake of understanding better, let's assume the address of a variable var.
If we assume address of a variable var as 1024 then the output of the above program will be,
Address of var = 1024 ptr is pointing to an address 1024 Value stored at ptr = a