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. uni-app map组件关于marker标记点动态设置的问题

    marker是Array类型,赋值的时候只能对整个数组进行更改赋值,不能只改变内部的对象,亲测Vue.$set()也不行 this.marker = [ { latitude: 39.90, long ...

  2. springcloud zuul shiro网关鉴权并向服务传递用户信息

    1.pom文件 <dependencies> <!--eureka客户端--> <dependency> <groupId>org.springfram ...

  3. Netty数据如何在 pipeline 中流动

    前言 在之前文章中,我们已经了解了pipeline在netty中所处的角色,像是一条流水线,控制着字节流的读写,本文,我们在这个基础上继续深挖pipeline在事件传播 Unsafe对象 顾名思义,u ...

  4. Markdown For EditPlus插件使用说明(基于EditPlus快速编辑Markdonw文件,写作爱好者的福音来啦)

    Markdown For EditPlus插件使用说明 开发缘由 特点好处: 中文版使用说明 相关命令(输入字符敲空格自动输出): EditPlus常用快捷键: 相关教程: English descr ...

  5. ABP Framework 5.0 RC.1 新特性和变更说明

    .Net 6.0 发布之后,ABP Framework 也在第一时间进行了升级,并在一个多星期后(2021-11-16)发布了 5.0 RC.1 ,新功能和重要变更基本已经确定. 5.0版本新特性 新 ...

  6. 【TcaplusDB知识库】如何部署TcaplusDB Local 版

    [TcaplusDB知识库]部署TcaplusDB Local 版的准备操作 1. 版本介绍 TcaplusDB Local版,是为用户提供的一个满足本地开发调试的版本(基于Docker部署的可下载版 ...

  7. 如何在C#中使用Google.Protobuf工具

    protobuf是一个语言无关.平台无关的序列化协议,由谷歌开源提供.再加上其高性能.存储占用更小等特点,在云原生的应用中越来越广泛. 在C#中主要有两种方法来使用protobuf协议,nuget包分 ...

  8. 【Tool】IntelliJ IDEA 使用技巧

    IntelliJ IDEA 使用技巧 2019-11-06  20:51:43  by冲冲 1.快捷键 Ctrl+w //括出相关范围 Ctrl+shift+f //按照代码段在全局搜索 Ctrl+f ...

  9. 整理记录一些好用的随机图API

    最近自己博客使用的随机图API有些不稳定,自己又去搜集了一些有意思的随机图API,这里做一个整理记录 注意!!!本文链接最后测试时间----2021年11月21日 主题作者Tagaki的API(有时候 ...

  10. vue项目中使用 SheetJS / js-xlsx 导入文件

    原表格样式; 导入效果: 1.  安装 npm install xlsx 2. 在App.vue 中引入xlsx import * as XLSX from 'xlsx'; // 数据导出导入所需要的 ...