Size of variable | SoloLearn: Learn to code for FREE!


Size of variable

Int var=5532; Int*varsize=var; Cout<< //i want to print pointers size in bytes?

8/18/2016 5:46:19 PM


3 Answers

New Answer


int var = 5532; int *varsize = &var; std::cout << sizeof(varsize); Regardless of the data type they are pointing to, pointers have fixed size and is related to the architecture. On 32-bit machine the size of a pointer is 32bits (4 bytes), while on 64 bit machine it is 8 bytes.


And what if i want to print size of var


int var = 5532; int *varPtr = &var; cout<<sizeof(var)<<endl; //without using a pointer cout<<sizeof(*varPtr)<<endl; //using a pointer