Size of variable | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Size of variable

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

18th Aug 2016, 5:46 PM
vishwas
vishwas - avatar
3 Answers
+ 1
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.
18th Aug 2016, 6:37 PM
0xfz13
0
And what if i want to print size of var
19th Aug 2016, 5:31 AM
vishwas
vishwas - avatar
0
int var = 5532; int *varPtr = &var; cout<<sizeof(var)<<endl; //without using a pointer cout<<sizeof(*varPtr)<<endl; //using a pointer
19th Aug 2016, 6:28 PM
Youssef