Print size of different types Using Pointer in C++
Definition:
- Pointer is a variable that holds the address of another variable.
- Pointer variable also takes same memory as of actual data type.
Pointer Syntax:
pointer_vaibale = &variable;
Sizeof Definition:
sizeof returns the size of a variable or data type
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 C++ Program,C++ Pointer Examples */
// Header Files
#include <iostream>
#include<conio.h>
using namespace std;
int main() {
// Declare Variables
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;
cout << "Pointer C++ Example Program : Print Size of Different types Using sizeof\n";
cout << "\n[sizeof(a) ]: = " << sizeof (a);
cout << "\n[sizeof(*pa) ]: = " << sizeof (*pa);
cout << "\n[sizeof(b) ]: = " << sizeof (b);
cout << "\n[sizeof(*pb) ]: = " << sizeof (*pb);
cout << "\n[sizeof(c) ]: = " << sizeof (c);
cout << "\n[sizeof(*pc) ]: = " << sizeof (*pc);
cout << "\n[sizeof(d) ]: = " << sizeof (d);
cout << "\n[sizeof(*pd) ]: = " << sizeof (*pd);
cout << "\n[sizeof(e) ]: = " << sizeof (e);
cout << "\n[sizeof(*pe) ]: = " << sizeof (*pe);
return 0;
}
Sample Output:
Pointer C++ 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
C++ Pointer Example Programs
- Simple Pointer Example Program In C++
- 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 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
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Example Program For Copy Constructor In C++
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Factorial Using Function Example Program In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program For Constructor In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Example Program For Constructor Overloading In C++
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Do While Loop Example Program In C++
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Exception Handling Divide by zero Using C++ Programming