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.
By IncludeHelp Last updated : March 10, 2024

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.

Printing size of different types of pointer 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 ~~~

C Pointer Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.