+ 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 Respuesta
+ 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