c++ - Fundamental Data Types Program -
c++ - Fundamental Data Types Program -
i wrote next code:
#include <iostream> #include <iomanip> using namespace std; int main(){ char c; int i; short int j; long int k; float f; double d; long double e; cout << "the size of char is: " << sizeof c << endl; cout << "the size of int is: " << sizeof << endl; cout << "the size of short int is: " << sizeof j << endl; cout << "the size of long int is: " << sizeof k << endl; cout << "the size of float is: " << sizeof f << endl; cout << "the size of double is: " << sizeof d << endl; cout << "the size of long double is: " << sizeof e << endl; system("pause"); homecoming 0; }
the purpose of programme print out size of fundamental info types, think have accomplished. other purpose of programme print size of pointer each of these info types. i'm having hard time figuring out how this. understand pointer variable stores address of variable , pointers involve deference operator (*). can please provide suggestion? i'm not looking answer, nudge in right direction.
int *p; // p pointer int
so sizeof pointer be: sizeof p
, print as:
cout << "the size of int pointer is: " << sizeof p << endl;
this need print other pointers' sizes.
dereferencing done when want access pointer pointing to. e.g.
int = 5; int *p = &i; *p = 6; *p = *p + 1; //etc
here, want size of pointers. no dereferencing needed.
c++ pointers types primitive-types
Comments
Post a Comment