Pointers in C

I know there are astronomical amount of articles, books, blogs have written so far on topic Pointers in C. However in this post I am trying to simplify this very topic in my own way.

To start with Pointer is a variable in C, which holds address of other variables.


  • Pointers can contain address of char variables
  • Pointers can contain address of int variables
  • Pointers can contain address of float variables
  • Pointers can contain NULL
  • Pointers can contain address of other pointer variables

You can create a pointer by creating a variable with the name starting with * asterisk. So a Pointer can be created as below,


  • First statement in above code can hold address of an integer variable.
  • Second statement in above code can hold address of a character variable
  • Third statement in above code can hold address of float variable

After declaring a pointer variable, address of simple variable can be assigned as below,


Different types of variable takes different space in memory. For example an integer variable will take 2 bytes, float will take 4 bytes and character variable will take 1 byte in memory. We can depict language C memory consumption by different kind of variables as below,


Now assume that you have created an integer pointer and assigned values to that as below,


There are two variables in above code snippet. Let us see how they point to different values. Assume that memory address containing value of variable var1 is 2000. You can find out from below image that var1 contains values 99 and its address in memory is 2000. Pvar1 is a pointer and it contains 2000 as value.


Let us go ahead and print various values.


One by one try to understand above lines of codes,

  1. Line 1 will print value of var1 which is 99
  2. Line 2 will print value of var1 again. Because pvar1 is pointer which contains address of var1. So to print value at that address we use * operator. Hence second line of above code will print value 99
  3. Third line will print address of var1. Address can be accessed with address operator (&)
  4. Fourth line will print address of var1. Since pvar1 is a pointer variable so printing this value will be address of the variable it contains
  5. Fifth line will print value 99. Because we are printing applying pointer variable * on address operator &.

So we can put output of above code snippets as below,


So I end this post with hope that you have some clarification of Pointers in C now. Code from above discussion is given below for your reference,

#include "stdafx.h"

void main()
int var1 =99;
int *pvar1 ;
pvar1 = &var1;


char var2 ='a';
char *pvar2 ;
pvar2 = &var2;



Expected output of above code is as below. Have in mind that address value could be differ in your environment.


I hope you find this post useful. Thanks for reading.

Published by

Dhananjay Kumar

Dhananjay Kumar is Developer Evangelist for Infragistics. He is a 8 times Microsoft MVP and well respected Developer Advocate in India.He is the author of 900+ Blog Posts, and can often be found speaking around India at conferences and hosting free workshops for programmers across the country. So far, he has hosted 60 free workshops on various topics like JavaScript, Angular, WCF, ASP.NET MVC, C#, Azure etc. Follow him on twitter @debug_mode for all the updates about his blog posts and workshops. You can send him email at debugmode [at] outlook [dot] com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s