find size of an object of a class

What will be the output of the following program?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
class publisher
{
public:
double turnover;       
char pname[15];
char hoffice[15];
char address[25];
char phone[3][10];
};
main()
{
      publisher b;
      cout<<sizeof(b);
      system("PAUSE");
      return 0;
}
  Put the code you need help with here.
What will be the output of the following program?


The output is implementation-defined.
... but it is probably 96:
We can use the memory analysis tool pahole to see how individual members are packed.
https://godbolt.org/z/1x5Khg

Last edited on
Topic archived. No new replies allowed.