Print size of different types Using Pointer in C
Definition:
- Pointer is the variable that holds the address of another variable.
- Poniter variable also take same memory of actual data type.
Poniter Syntax:
pointer_vaibale = &variable;
Sizeof Definition:
sizeof returns the size of a variable or datatype
Sizeof Syntax
sizeof (data_type)
Simple Program for Print size of different types Using Pointer in C
/* Simple Program for Print size of different types Using Pointer in C*/
/* Print Pointer Address Program,C Pointer Examples */
#include <stdio.h>
int main() {
int a = 10;
int *pa = &a;
char b = 'x';
char *pb = &b;
float c = 10.01;
float *pc = &c;
double d = 10.01;
double *pd = &d;
long e = 10.01;
long *pe = &e;
printf("Pointer Example Program : Print Size of Different types Using sizeof\n");
printf("\n[sizeof(a) ]: = %d", sizeof(a));
printf("\n[sizeof(*pa) ]: = %d", sizeof(*pa));
printf("\n[sizeof(b) ]: = %d", sizeof(b));
printf("\n[sizeof(*pb) ]: = %d", sizeof(*pb));
printf("\n[sizeof(c) ]: = %d", sizeof(c));
printf("\n[sizeof(*pc) ]: = %d", sizeof(*pc));
printf("\n[sizeof(d) ]: = %d", sizeof(d));
printf("\n[sizeof(*pd) ]: = %d", sizeof(*pd));
printf("\n[sizeof(e) ]: = %d", sizeof(e));
printf("\n[sizeof(*pe) ]: = %d", sizeof(*pe));
return 0;
}
Sample Output:
Pointer Example Program : Print Size of Different types Using sizeof
[sizeof(a) ]: = 4
[sizeof(*pa) ]: = 4
[sizeof(b) ]: = 1
[sizeof(*pb) ]: = 1
[sizeof(c) ]: = 4
[sizeof(*pc) ]: = 4
[sizeof(d) ]: = 8
[sizeof(*pd) ]: = 8
[sizeof(e) ]: = 4
[sizeof(*pe) ]: = 4
/* Output may vary based on system */
C Pointer Example Programs
- Simple Pointer Example Program
- Simple Program for Print address of Variable Using Pointer in C
- Pointer Simple Example Program with Reference operator (&) and Dereference operator (*)
- Simple Example Program for Swap Numbers Using Pointers In C
- Print size of different types Using Pointer in C
- Simple Program for Add Two Numbers Using Pointer in C
- Simple Program for Increment and Decrement Integer Using Pointer in C
- Simple Program for Increment and Decrement Floating Point Using Pointer in C
- Simple Program for Find a difference between two Numbers Using Pointer in C
- Simple Program for Change the value of constant integer Using Pointer in C
- Simple Program for Print String Using Pointer in C
- Simple Program for Count vowels String Using Pointer in C
- Simple Program for Length of String Using Pointer In C
- Pointer to Pointer or Double Pointer Example Program In C
- Simple Program for Pointer and Array Example in C
- Simple Program for Sum of Integer an array using pointers in C
- Simple Program for Read, Print and Sum of Integer in an array using pointers in C
- Simple Example Program for Passing pointers to functions In C
- Simple Example Program for Area Of Circle Using Pointer In C
Read More Articles
- Use of getch(),getche() and getchar() in C
- Switch Case Statement Example Program In C Programming Language
- C Character Set
- Convert a Floating-point value to an Integer in C
- Data Input and Output gets and puts Example Program In C
- Special Operators In C
- Pointer Representation and Pointer Example Programs
- C Data Input and Data Output
- Simple While Loop Example Program In C Programming Language
- Data Output printf and putchar Example Program In C
- C Introduction
- C Operators
- Storage Classes In C
- C Pointers
- File Management
- C Identifiers
- Loop Control Statements
- Hello World - Simple C Program
- C Array
- Single Character Output Function : putchar()
- C Reserve Words
- C Specific Properties and Implementation
- If else Statement Example Program In C Programming Language
- If Statement Example Program In C Programming Language
- Confusing Array in C ( Array Representation and Initialization )