Why it prints 1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why it prints 1

#include<iostream> using namespace std; class a{}; int main() { cout<<sizeof(a); return 0; }

9th Nov 2018, 10:46 AM
Rajan Pandey
Rajan Pandey - avatar
1 Answer
+ 1
Empty structs/classes have a size of 1 so that it can exist in memory. If it had 0 then pointer arithmetic would fall apart.
9th Nov 2018, 1:58 PM
Dennis
Dennis - avatar