ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Programming Languages

Pointers in C

Updated on July 10, 2012
C Programming, Free C Language Tutorials.
C Programming, Free C Language Tutorials.

In this tutorial I am going to discuss what pointer is and how to use them in our C program. Many C programmer thinks that pointer is one of the difficult topic in C language but it’s not completely true. It is difficult to understand in comparison of other secondary (array, structure etc.) data types available in C. Pointer in C seems to be difficult because it works directly with computer memory (RAM).

When we declare any variable in C, for example integer variable, it occupies a memory according to its size (here 2 bytes). As it occupies a memory so it’s natural to have an address for this location so that it can be referenced later by CPU for manipulation. But before we begin with Pointer we must have some idea on the operators we are going to use in Pointer programming.

The ‘*’ And ‘&’ Operators

Take a look on the following declaration,

                int x=10;

When we make such declaration how C compiler treat this statement:

  1. Reserve memory space for this integer value.
  2. Name this memory location as x.
  3. Store the value 10 at this location.

This can be illustrated by a simple diagram:

Integer variable location in memory.
Integer variable location in memory.

So when we declared an integer variable x and assigned value 10 then compiler occupied a 2 byte memory space at memory address 65325 and stored value 10 at that location. Compiler named this address x so that we can use x instead of 65325 in our program. But we can use address or variable in our program and both will point to the same value (example given below).

The memory address of a variable could differ from PC to PC and entirely depends on available free space in memory at time of program execution. As this differs from PC to PC thus we cannot rely on that address (numeric value representing variable address) and we cannot use this address in our program. But have you noticed one thing that address is an integer.

We can print address of any variable or function, following program shows how we can do that:

Address of variable example.


void main()
	int i=9;

	printf("Value of i : %d\n",i);
	printf("Address of i : %u",&i);


This is a very simple c program which prints value and address of an integer. But did you notice line no. 10 in above program? This line output the address of i variable and to get address of i variable we have used ampersand (&) operator. This operator is known as "Address of" operator and we already used this operator many times in our program, just recall scanf statement which is used to accept input from computer keyboard. So when we use ampersand operator (&i) before any variable then we are instructing c compiler to return its address instead of value.

Another operator we going to deal with in this entire pointer tutorial is "*" called "Value at address" operator. It is the same operator which we use for multiplication of numbers. As the name suggest, "value at address" operator returns value stored at particular address. The "value at address" operator also called indirection operator. Following example extends above C program and puts "value at address" operator in action.

Value at address (*) example


void main()
	int i=9;

	printf("Value of i : %d\n",i);
	printf("Address of i : %u\n",&i);
	printf("Value at address of i : %d",*(&i));

Output of "value at address" operator example.
Output of "value at address" operator example.

Now in this program notice line no. 11 and use of ‘&’ and ‘*’ operators also see the output of program which prints value of variable i and *(&i) same. This is how these two operator works.

You must have clear idea of ‘&’ and ‘*’ operator usage before you jump into pointer because pointer deals with these to operator. If you find any difficulty then post your doubts and I will try to clear your doubts.

What is Pointers in C Programming?

A pointer is a secondary data type (also known as derived data type) in C. It is built from one of the primary data types available in C language. Basically pointer contains memory address of other variable or function as their value. As pointer deals with memory address, it can be used to access and manipulate data stored in memory.

Benefits of using Pointer in C Program

Pointer is one of the most exciting features of C language and it has added power and flexibility to the language. Pointer is in C language because it offers following benefits to the programmers:

  1. Pointers can handle arrays and data table efficiently.
  2. Pointers support dynamic memory management.
  3. Pointer helps to return multiple values from a function through function argument.
  4. Pointer increases program execution speed.
  5. Pointer is an efficient tool for manipulating structures, linked lists, queues stacks etc.

We can achieve these and much more benefits from pointer only if we can use it properly.

Pointer with an example

Since this tutorial is already become lengthy so I am going to give a small example on how we can use pointer in our C program. Of course we will discuss remaining part in my next pointer tutorial.

Syntax:            datatype *pointer_name;

Example :        int *iPtr;

                        float *fPtr;

Pointer Example


void main()
	int i=9, *ptr;

	printf("Value of i : %d\n",i);
	printf("Address of i : %u\n",&i);
	printf("Value of ptr : %u\n",ptr);
	printf("Address of ptr : %u\n",&ptr);
	printf("Ptr pointing value : %d", *ptr);


In the above example in line no. 6 we have declared an integer i and assigned 9 to it. Along with variable i, we have also declared an integer pointer. To declare a pointer of any data type we just need to put an * (asterisk) before variable name or identifier. In our example ptr is an integer variable and is capable of holding address of any integer variable.

Remember one thing integer pointer can hold only integer variable address, you cannot use integer pointer to hold address of float or char variable. To hold char or float variable address in a pointer you need to declare char or float pointer respectively.

In line no. 7 we assigned integer variable i’s address to ptr, now ptr is pointing to i. Line no 10 prints value of i and line no. 11 prints address of i. Next line prints value stored in ptr pointer variable, line no. 13 prints address of ptr pointer. As pointer is different entity so it also requires space in memory. Memory occupied by a pointer depends on its data type. Integer pointer will occupy 2 bytes whereas character pointer will occupy 1 byte. Finally line no. 14 prints the value of address stored in ptr pointer i.e. value of i. And to print value of stored address in a pointer we need write *pointer variable name (in our example *ptr). A memory map will help you to understand this.

Pointer memory map.
Pointer memory map.
Pointer example output.
Pointer example output.

If you find any difficulty or error in this article then please let me know through comment box.

Thank you for visiting my free C pointer tutorial. 

C Programming Learner's Poll

Is this tutorial helpful to understand basic C Pointer concept?

See results


    0 of 8192 characters used
    Post Comment

    • profile image

      Akshay 4 years ago

      What is the meaning of


    • profile image

      5 years ago

      segment of program displays the contents of variables X and Y. Add two more lines of code to print the address of the two variables using the address operator.

      int X = 5, Y = 10;

      printf(“The value of X: %d\n”, X);

      printf(“The value of Y: %d\n”, Y);

    • profile image

      Umang 6 years ago

      Very Good For who have start learn of Pointer

    • profile image

      sriman 6 years ago

      thanqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq sirrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

    • profile image

      Thiva 6 years ago me to understand * and & in pointers.

    • profile image

      bhavani lalitha 6 years ago

      very nice and u can give a lot of information thank you so much

    • profile image

      some guy.. ^^ 6 years ago

      The title really is confusing. At the first glance I thought it would be pointers as in GUIDE but since I have knowledge in programming, I was able to easily adapt with the idea.

      Layout is great, lots of ads but not overcrowded unlike most of blogs I have seen ^__^

    • profile image

      mohammed ali 6 years ago

      good i have well understood

    • profile image

      AJIT 6 years ago


    • profile image

      goldi 6 years ago

      its sufficient to beginners,but i confuse of this Q. i.e. how many types of pointer?

    • profile image

      Manthabi 6 years ago

      This is gorgeous. For the first time I'm beginning to understand the concept of pointers

    • profile image

      Musau 6 years ago

      Excellent tutorial especially for beginners

    • profile image

      manjot 6 years ago

      a good suggestion buddy ask ques related to topics also

    • profile image

      mahendrababu 6 years ago

      u hv done a good job

    • profile image

      Gautham 6 years ago


    • profile image

      Logasubramaniyam 6 years ago

      why we are using %u what is the use of it?will u help pls

    • rajkishor09 profile image

      RAJKISHOR SAHU 6 years ago from Bangalore, Karnataka, INDIA

      @Mr. Amit Shaw: i like your way of appreciation. Thanks buddy

    • profile image

      Mr. Amit Shaw 6 years ago


      void main()



      printf("This Site is Just Awesome /n");

      printf("Thanks Thank you Very Much Admin");



    • profile image

      javgal-shimoga 6 years ago

      thumba dhanyavaadagalu - artha vayithu !

      i was hoping you could give an example on "structure in a structure " in your blog .

      thank you


      javgal -benglooru

    • profile image

      Santosh Kedar 6 years ago

      Thank u sir..............

    • profile image

      ronel 7 years ago

      thanks!! this is useful

    • profile image

      sunil 7 years ago


      but i need some array pointer

    • profile image

      aruna 7 years ago

      its vry gud explanations

    • profile image

      surya 7 years ago

      thax for ur pointers concept,now i am clear about pointers.

    • profile image

      leena 7 years ago

      really ur work is so good..... well done......but we want more on "MACROS"

    • profile image

      PARIJAT 7 years ago


    • profile image

      Blake 7 years ago

      Awesome post, but one point is not quite accurate. You mentioned that "Memory occupied by a pointer depends on its data type. Integer pointer will occupy 2 bytes whereas character pointer will occupy 1 byte." This is not true. All pointers occupy the same amount of space on a given platform, regardless of the data type to which they point. For example, on a 32-bit system, a pointer will occupy 4 bytes of memory. On a 64-bit system, a pointer will occupy 8 bytes of memory. This is true regardless of whether the pointer points to an int, char, float, or any other type of data.

    • sambaran08 profile image

      sambaran08 7 years ago from India

      Very nice,but next time explain step by step with many example,

      visit my blog

      and follow me

    • profile image

      jalesingh 7 years ago

      Its OK but I want more examples on C pointer.

    • profile image

      Manish Arya 7 years ago

      this methode is too good very much for understand the pointer....anybody

    • profile image

      mudd 7 years ago

      it is just AWESOME.. you really are a genius because you know how to break down this type of topic into the basic of basics for first time programmers like me.. i just couln't understand the way my instructor taught this to our class..such a bummer

      thanks again!

    • profile image

      Madhavi Devineni 7 years ago

      Hi! This is Madhavi

      Your Pointers topic is nice. But, I could not understand, "How the pointer and arrays are the datatypes?"

    • profile image

      shruti singh 7 years ago

      nice presentation for basic concept, but need more to be expalined for implementation

    • profile image

      rekha 7 years ago

      i want to improve programming in please guide me in programming.

    • gauri1234 profile image

      gauri1234 8 years ago

      you have covered a lot..i wished too but "u well done"

    • profile image

      subhash sharma 8 years ago

      ur effort realy very effective , what nice explain pointer

    • profile image

      k.rajesh 8 years ago

      c commandas used in c++

    • profile image

      Brad Masters 8 years ago

      Very nice presentation

      How about a comparison

      C, C++, C#

      doing the same thing.

    • nicomp profile image

      nicomp really 8 years ago from Ohio, USA

      %p also works as a print format for a pointer. A memory address is not, strictly speaking, an integer data type. It may be a segment/offset combination, or some other data structure. Specific information is a function of the computer architecture on which the C program is executing.

      int x;

      x = 123;

      printf("%p", (void *)&x); // prints the address of the integer x

    • nekros729 profile image

      nekros729 8 years ago

      Haha, the title confused me a little bit, I thought you were talking about tips. I'm always up for improvement. =)

    • profile image

      puspak 8 years ago

      it is awesome


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: ""

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)