+ 1

Purpose of the sizeof operator and how to use it?

13th Nov 2016, 2:38 PM
Kavish Hamza
Kavish Hamza - avatar
3 Réponses
+ 2
we use sizeof operator to know the size of any variable for example if we want to know the size of character a we type int x; char a; x=sizeof(a); cout<<x;
30th Jan 2017, 4:23 PM
shivam
shivam - avatar
0
The sizeof operator is used to calculate the space used by a variable (in bytes) in memory. For int, it is 4 bytes, for char it is 1 byte etc. It also varies from compiler to compiler. void main() { int x=5,a[4]; char c; int size=sizeof(x); int size1=sizeof(a); int size2=sizeof(c); cout<<"Size of x is "<<size<<" bytes"; cout<<"\nSize of Array is "<<size1<<" bytes"; cout<<"\nSize of c is "<<size2<<" bytes"; }
28th Jan 2017, 6:39 PM
Nitesh Lekhi
Nitesh Lekhi - avatar
0
sizeof is used to find bit size of variable to find size of datatype use sizeof(datatype) to find size of variable use sizeof variable also it is ued to find size of array
30th Jan 2017, 8:50 PM
bhavneet singh
bhavneet singh - avatar