How to use sizeof | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to use sizeof

20th Oct 2016, 12:39 PM
MUHAMMAD ILHAM
MUHAMMAD ILHAM - avatar
4 Answers
+ 5
sizeof() gives you the size of a data type or variable, in bytes. cout << sizeof(int) << endl; int ans = 42; cout << sizeof(ans) << endl; Example of use: get the length (= number of elements) of an array: int arr[10] = {0}; int len = sizeof(arr)/sizeof(arr[0]);
20th Oct 2016, 4:17 PM
Zen
Zen - avatar
+ 1
thanks jishnu
20th Oct 2016, 1:53 PM
MUHAMMAD ILHAM
MUHAMMAD ILHAM - avatar
0
Cout<<Sizeof(x); OR i=sizeof(x); where x is a variable or constant
20th Oct 2016, 1:47 PM
Jishnu
Jishnu - avatar
0
Welcome man
20th Oct 2016, 1:54 PM
Jishnu
Jishnu - avatar