2

I have recently come across a question in one of my interview.

What is the difference between C++ struct & class in terms of memory ??

I know they are same in all aspects except access specifiers while inheriting & in case of member variables.

Apart from this is there a real difference in terms of memory (may be memory allocation or destruction or memory management whatever) ????

Edit: I am not pretty sure why did the interviewer asks this question when there is no difference. I have found similar question here see the 2nd comment down to that link, he is asking a same question but no answer. I think there should be a diff.

Thanks In Advance.

NDestiny
  • 1,133
  • 1
  • 12
  • 28
  • 4
    No difference what so ever. – 101010 Apr 08 '16 at 19:01
  • I am not pretty sure why did the interviewer asks this question when there is no difference. I have found similar question [here](http://www.geeksforgeeks.org/g-fact-76/) see the 2nd comment down to that link, he is asking a same question but no answer. I think there should be a diff. – NDestiny Apr 08 '16 at 19:18

1 Answers1

5

In C++, a class and a struct are completly identical except for the facts that structs default to public access and inheritance whereas class defaults to private.

As far as memory layout there is no difference what-so-ever.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70