#include<iostream.h> #include<conio.h> class Temperature { private: double magni
ID: 3619202 • Letter: #
Question
#include<iostream.h> #include<conio.h> class Temperature { private: double magnitude; char scale; }; int main() { Temperature t1; cout<<sizeof(t1)<<endl; return 0; } the output of the above code is 16 while it should be the(size of double+size of char)which is 8. Would u please explain why it is 16. #include<iostream.h> #include<conio.h> class Temperature { private: double magnitude; char scale; }; int main() { Temperature t1; cout<<sizeof(t1)<<endl; return 0; } the output of the above code is 16 while it should be the(size of double+size of char)
which is 8. Would u please explain why it is 16.
Explanation / Answer
please rate - thanks when sizeof is applied to a variable, or array it returns thenumber of bytes allocated for the variable or array however when sizeof is applied to a class the value returned is the numberof bytes for the objects in the class, plus any padding required tobe added to align all the memebers of the class on the boundariesas specified by the compiler
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.