Home » C programs » C pointer programs

C program to print size of different types of pointer variables.



In this C program, we will check what will be the size of different types of pointer variables? Here, we will print the size of different types of pointer variables.
Submitted by IncludeHelp, on April 26, 2018

Any type of pointer variable takes the same memory bytes in the memory, because they are used to store the memory addresses on other type of variables.

Let’s take an example - There are two pointers 1) integer pointer and 2) char pointer, integer pointer will take 4 bytes (in case of, 32 bits compiler) and will store the address of integer variables only. char pointer will also take 4 bytes but it will store the address of only char variable.

In this C program, we are testing the same by printing the size of different types of pointers.

C program to print sizes of different type of pointers

/*C program to print size of different types of pointer variables.*/
#include <stdio.h>
 
int main()
{
    printf("\nsize of char pointer: %d"     ,sizeof(char*));
    printf("\nsize of int pointer: %d"      ,sizeof(int*));
    printf("\nsize of float pointer: %d"    ,sizeof(float*));
    printf("\nsize of long int pointer: %d" ,sizeof(long int*));
    printf("\nsize of double pointer: %d\n" ,sizeof(double*));
    return 0;
}

Output

    size of char pointer: 4
    size of int pointer: 4
    size of float pointer: 4
    size of long int pointer: 4
    size of double pointer: 4

~~~~ Output depends on the system architecture,
~~~~ but each type of pointer will take same memory space ~~~






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.