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 ...
随机推荐
- CSS学习(二)选择符
元素选择符:以元素名作为选择符(span{ color: red; }) 群组选择符:将两个选择符用逗号隔开构成群组(span, div{ color: red; }) 通用选择符:通用选择符(*)将 ...
- C++ 指针的引用和指向引用的指针
指向引用的指针 简单使用指针的一个例子就是: int a = 1; int *p = &a; 预先强调: 没有指向引用的指针 原因: 因为引用 不是对象,没有地址. 但是指向引用的指针是什么形 ...
- offsetX各种值总结
pageX: 页面X坐标位置 pageY: 页面Y坐标位置 screenX: 屏幕X坐标位置 screenY: 屏幕Y坐标位置 clientX: 鼠标的坐标到页面左侧的距离 clientY: 鼠标的坐 ...
- leakcanary内存泄漏:此篇有加了内存泄漏的apk demo
概括: ·用Android studio写一个demo ·配置leakcanary ·加入内存泄漏代码片段 ·安装apk 验证结果 ·源码地址 一.android ...
- airflow redis sentinel
获取master name subscribe __sentinel__:hello mysql plugin table not found mysqld --initialize-insecure ...
- Python基础(slice切片)
l = ['傻狗1','傻狗2','傻狗3','傻狗4','傻狗5','傻狗6'] print(l[0:3])#['傻狗1', '傻狗2', '傻狗3'] numbers = list(range(1 ...
- OpenCV常用操作函数大全
https://blog.csdn.net/Vici__/article/details/100714822 目录 cv2常用类: 1.图片加载.显示和保存 2.图像显示窗口创建与销毁 3.图片的常用 ...
- [Aizu2993]Invariant Tree
若$(i,j)\in E$,实际上会不断推出$(p_{i},p_{j})\in E,(p_{p_{i}},p_{p_{j}})\in E,...$ 考虑将$i$向$p_{i}$连边得到了一张(由若干个 ...
- Vue: 一个简单的Vue2.0 v-model双向数据绑定的实现,含源代码,小白也能看懂
首先说一下原理吧 View层(dom元素)的变动如何响应到Model层(Js变量)呢? 通过监听元素的input事件来动态的改变js变量的值,实际上不是改变的js变量的值,而是改变的js变量的gett ...
- CSS动画--让div动起来
CSS动画 今天在写代码时候,遇到了css动画效果如何实现的问题,经过查阅和实践,总结出一下结论. transition transition 指定动画变化的对应属性 以及动画的执行时间. 例如:tr ...