Output of C++ Program | Set 1
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的更多相关文章
- Output of C++ Program | Set 18
Predict the output of following C++ programs. Question 1 1 #include <iostream> 2 using namespa ...
- Output of C++ Program | Set 17
Predict the output of following C++ programs. Question 1 1 #include <iostream> 2 using namespa ...
- Output of C++ Program | Set 16
Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 using namespac ...
- Output of C++ Program | Set 15
Predict the output of following C++ programs. Question 1 1 #include <iostream> 2 using namespa ...
- Output of C++ Program | Set 14
Predict the output of following C++ program. Difficulty Level: Rookie Question 1 1 #include <iost ...
- Output of C++ Program | Set 13
Predict the output of following C++ program. 1 #include<iostream> 2 using namespace std; 3 4 c ...
- Output of C++ Program | Set 11
Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 using namespac ...
- Output of C++ Program | Set 9
Predict the output of following C++ programs. Question 1 1 template <class S, class T> class P ...
- 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 ...
- Output of C++ Program | Set 6
Predict the output of below C++ programs. Question 1 1 #include<iostream> 2 3 using namespace ...
随机推荐
- supervisor安装
supervisor管理进程,是通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,所以我们只需要将要管理进程的可执行文件的路径添加到supervisor的配置文件中 ...
- CSS学习笔记:display属性
目录 一.display属性概述 1. 块级元素和行内元素的区别 2.常见的块级元素和行内元素 3. display属性常见的属性值 二.测试display取各属性值的效果 1. 测试inline和b ...
- Mysql基础教程:(七)MySQL基础练习
MySQL基础练习 一.创建student和score表 CREATE TABLE student (id INT(10) NOT NULL PRIMARY KEY ,name VARCHAR(20) ...
- 【python+postman接口自动化测试】(1)网络基础知识
一.IP地址 就像每个人都有一个身份证号码 IP地址是IP协议提供的一种统一的地址格式,它为互联网上的每一个网络和每一台主机分配一个逻辑地址. 查看IP命令: Windows: ipconfig Li ...
- 【数据结构&算法】09-队列概念&参考源码
目录 前言 队列的定义 队列的抽象数据类型 循环队列与链式队列对比 循环队列 特点 定义 循环队列相关计算 链式队列 定义 阻塞队列 并发队列 代码实现 循环队列代码 链式队列实现 前言 李柱明博客: ...
- 访问kubernetes CRD的几种方式
访问kubernetes CRD的几种方式 最近在使用代码操作VictoriaMetrics Operator的CRD资源的过程中,探究了集中访问CRD资源的方式.下面以VictoriaMetrics ...
- 学信网改绑手机号码,但是忘记了老号码怎么办?利用node.js + puppeteer 跑脚本实现改绑手机号
最近登录学信网发现自己学信网上绑定的手机号码不是目前自己使用的手机号码,于是想改绑手机号,但是发现不记得之前的手机号码了: 于是百度各种方法都无济于事:也不想重新注册账号,最后看见一篇文章通过Pyth ...
- IO流(一)
内容概要: Java以流的形式处理所有输入和输出.流是随通信路径从源移动到目的地的字节序列. 内存与存储设备之间传输数据的通道 流的分类: 按方向 输入流:将存储空间中的内容读到内存中 硬盘--& ...
- Python基础(定制类)
文章转载自廖雪峰老师Python课程博客,仅供学习参考使用看到类似__slots__这种形如__xxx__的变量或者函数名就要注意,这些在Python中是有特殊用途的. __slots__我们已经知道 ...
- 菜鸡的Java笔记 第二十六 - java 内部类
/* innerClass 从实际的开发来看,真正写到内部类的时候是在很久以后了,短期内如果是自己编写代码,几乎是见不到内部类出现的 讲解它的目的第一个是为了解释概念 ...