struct 与 class 的区别

单选题 难度 3

#class#struct

把上一题的 class 换成 struct。

题目

下面代码的输出是( )。

struct S { int v = 5; };
// main: S s;  s.v = 8;  cout << s.v << endl;
  1. 8
  2. 5
  3. 0
  4. 编译错误:v 是私有的
来小码星球,动手写一遍 →