1// In C++, a class and a struct are COMPLETELY IDENTICAL
2// Except structs default to PUBLIC access and inheritance
3// Whereas class defaults to PRIVATE.
11) Members of a class are private by default and members of a struct are public
2by default.
3For example program 1 fails in compilation and program 2 works fine.
4
5/ Program 1
6#include <stdio.h>
7
8class Test {
9 int x; // x is private
10};
11int main()
12{
13 Test t;
14 t.x = 20; // compiler error because x is private
15 getchar();
16 return 0;
17}
18
19// Program 2
20#include <stdio.h>
21
22struct Test {
23 int x; // x is public
24};
25int main()
26{
27 Test t;
28 t.x = 20; // works fine because x is public
29 getchar();
30 return 0;
31}