Predict the output of below C++ programs.

  Question 1

 1 // Assume that integers take 4 bytes.
2 #include<iostream>
3
4 using namespace std;
5
6 class Test
7 {
8 static int i;
9 int j;
10 };
11
12 int Test::i;
13
14 int main()
15 {
16 cout << sizeof(Test);
17 return 0;
18 }

  Output: 4 (size of integer)
  

  static data members do not contribute in size of an object. So ‘i’ is not considered in size of Test. Also, all functions (static and non-static both) do not contribute in size.

  Question 2

 1 #include<iostream>
2 using namespace std;
3
4 class Base1
5 {
6 public:
7 Base1()
8 {
9 cout << "Base1's constructor called" << endl;
10 }
11 };
12
13 class Base2
14 {
15 public:
16 Base2()
17 {
18 cout << "Base2's constructor called" << endl;
19 }
20 };
21
22 class Derived: public Base1, public Base2
23 {
24 public:
25 Derived()
26 {
27 cout << "Derived's constructor called" << endl;
28 }
29 };
30
31 int main()
32 {
33 Derived d;
34 return 0;
35 }

  Ouput:
  Base1′s constructor called
  Base2′s constructor called
  Derived’s constructor called

  In case of Multiple Inheritance, constructors of base classes are always called in derivation order from left to right and Destructors are called in reverse order.

Output of C++ Program | Set 1的更多相关文章

  1. Output of C++ Program | Set 18

    Predict the output of following C++ programs. Question 1 1 #include <iostream> 2 using namespa ...

  2. Output of C++ Program | Set 17

    Predict the output of following C++ programs. Question 1 1 #include <iostream> 2 using namespa ...

  3. Output of C++ Program | Set 16

    Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 using namespac ...

  4. Output of C++ Program | Set 15

    Predict the output of following C++ programs. Question 1 1 #include <iostream> 2 using namespa ...

  5. Output of C++ Program | Set 14

    Predict the output of following C++ program. Difficulty Level: Rookie Question 1 1 #include <iost ...

  6. Output of C++ Program | Set 13

    Predict the output of following C++ program. 1 #include<iostream> 2 using namespace std; 3 4 c ...

  7. Output of C++ Program | Set 11

    Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 using namespac ...

  8. Output of C++ Program | Set 9

    Predict the output of following C++ programs. Question 1 1 template <class S, class T> class P ...

  9. Output of C++ Program | Set 7

    Predict the output of following C++ programs. Question 1 1 class Test1 2 { 3 int y; 4 }; 5 6 class T ...

  10. Output of C++ Program | Set 6

    Predict the output of below C++ programs. Question 1 1 #include<iostream> 2 3 using namespace ...

随机推荐

  1. 如何将声学的spectrogram(声谱图)重新反变换成时域语音信号

    最近在研究一些信号分析的事情,感兴趣如何将频谱信号反变换成时域信号.fft 与ifft可以顺畅的转变,但是这个是一帧信号,当时间较长的信号再一起是,通过反变换变成一帧一帧的时域信号,如何把他们拼接起来 ...

  2. SpringCloud升级之路2020.0.x版-30. FeignClient 实现重试

    本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 需要重试的场景 微服务系统中,会遇到在线发布,一般的发布更新策略是:启动一个新的,启动成功 ...

  3. 从源码分析 XtraBackup 的备份原理

    MySQL物理备份工具,常用的有两个:MySQL Enterprise Backup 和 XtraBackup. 前者常用于MySQL企业版,后者常用于MySQL社区版.Percona Server ...

  4. PHP 数组函数分类整理

    1.处理数组键名相关的函数: array_change_key_case - 返回字符串键名全为小写或大写的数组. array_key_exists - 检查给定的键名或索引是否存在于数组中 arra ...

  5. 15. mac安装多版本jdk

    一.jdk下载地址 jdk官网下载地址:http://jdk.java.net/archive/ 二.安装jdk Mac的JDK都是安装到一个指定目录的:/Library/Java/JavaVirtu ...

  6. 动画录屏软件-LICEcap

    越来越觉得脑子不够用了,不记博客根本找不到自己以前都干了些啥,自己学的东西用不到就特别难受,学完不用,重新捡起来跟嚼蜡一样难受. 接下来推荐一款动画截屏软件,短小精悍: https://www.coc ...

  7. Identity Server 4 从入门到落地(二)—— 理解授权码模式

    Identity Server 的目的是认证和授权,我们需要理解认证和授权的工作过程.这就需要了解OAuth 2.0的四种授权模式,下面这张图是授权码模式的工作过程,至少我在一开始看得一头雾水: 现在 ...

  8. 入坑 OI 249561092 周年之际的一些感想

    2018.2.10~2021.2.10 又是一年的 2 月 10 日,今天的到来意味着我 OI 生涯的第三年已经结束,即将开启 OI 生涯的第四年了.回顾这三年以来自己由懵懂.无知慢慢变成熟的历程,感 ...

  9. Codeforces 1373F - Network Coverage(模拟网络流)

    Codeforces 题面传送门 & 洛谷题面传送门 提供一个模拟网络流的题解. 首先我们觉得这题一脸可以流的样子,稍微想想可以想到如下建图模型: 建立源点 \(S,T\) 和上下两排点,不妨 ...

  10. 洛谷 P7360 -「JZOI-1」红包(Min-Max 容斥+推式子)

    洛谷题面传送门 hot tea. 首先注意到这个 \(\text{lcm}\) 特别棘手,并且这里的 \(k\) 大得离谱,我们也没办法直接枚举每个质因子的贡献来计算答案.不过考虑到如果我们把这里的 ...