小程序 || 语句

Program 1:

程序1:

#include <iostream>
using namespace std;
int main()
{switch (printf("Hello World")) {case 0x09:
cout << " India";
break;
case 0x0A:
cout << " Australia";
break;
case 0x0B:
cout << " USA";
break;
case 0x0C:
cout << " England";
break;
}
return 0;
}

Output:

输出:

Hello World USA

Explanation:

说明:

The above code will print "Hello World USA" on the console screen.

上面的代码将在控制台屏幕上打印“ Hello World USA”

As we know that printf() function prints data on the console screen and returns the total number of characters printed on the screen.

我们知道, printf()函数在控制台屏幕上打印数据,并返回屏幕上打印的字符总数。

printf("Hello World")

The above printf() function returns 11. And the hexadecimal equivalent of 11 is 0x0B, then case 0x0B will be executed.

上面的printf()函数返回11 。 并且十六进制的11等于0x0B ,那么将执行情况0x0B

And the final output is "Hello World USA".

最后的输出是“ Hello World USA”

Program 2:

程式2:

#include <iostream>
using namespace std;
int main()
{
int A = 10, B = 5, C = 2;
switch (A * ++B + C - 8) {
default:
cout << "Pakistan ";
case 0x09:
cout << "India ";
break;
case 0x0A:
cout << "Australia ";
break;
case 0x0B:
cout << "USA ";
break;
case 0x0C:
cout << "England ";
break;
}
return 0;
}

Output:

输出:

Pakistan India

Explanation:

说明:

The above code will print "Pakistan India " on the console screen. Here we pass an expression in the switch block. Based on the expression result, the case will be executed.

上面的代码将在控制台屏幕上打印“ Pakistan India” 。 在这里,我们在switch块中传递一个表达式。 根据表达式结果,将执行大小写。

Evaluate the expression step by step:

逐步评估表达式:

int A=10,B=5,C=2;
=A*++B+C-8
=10*6+2-8
=60+2-8
=54

The result of the expression is 54 and there is no such case is defined. Thus, the default case will be executed and then the case 0x09 will be executed (Because break statement is missing after in default case)

表达式的结果为54 ,没有定义这种情况。 因此,将执行默认情况 ,然后执行情况0x09 (因为在默认情况下缺少break语句 )

Then the final output "Pakistan India" will be printed on the console screen.

然后,最终输出“巴基斯坦印度”将打印在控制台屏幕上。

Recommended posts

推荐的帖子

  • C++ Switch Statement | Find output programs | Set 2

    C ++转换语句| 查找输出程序| 套装2

  • C++ Operators | Find output programs | Set 1

    C ++运算符| 查找输出程序| 套装1

  • C++ Operators | Find output programs | Set 2

    C ++运算符| 查找输出程序| 套装2

  • C++ const Keyword | Find output programs | Set 1

    C ++ const关键字| 查找输出程序| 套装1

  • C++ const Keyword | Find output programs | Set 2

    C ++ const关键字| 查找输出程序| 套装2

  • C++ Reference Variable| Find output programs | Set 1

    C ++参考变量| 查找输出程序| 套装1

  • C++ Reference Variable| Find output programs | Set 2

    C ++参考变量| 查找输出程序| 套装2

  • C++ Conditional Statements | Find output programs | Set 1

    C ++条件语句| 查找输出程序| 套装1

  • C++ Conditional Statements | Find output programs | Set 2

    C ++条件语句| 查找输出程序| 套装2

  • C++ goto Statement | Find output programs | Set 1

    C ++ goto语句| 查找输出程序| 套装1

  • C++ goto Statement | Find output programs | Set 2

    C ++ goto语句| 查找输出程序| 套装2

  • C++ Looping | Find output programs | Set 1

    C ++循环| 查找输出程序| 套装1

  • C++ Looping | Find output programs | Set 2

    C ++循环| 查找输出程序| 套装2

  • C++ Looping | Find output programs | Set 3

    C ++循环| 查找输出程序| 套装3

  • C++ Looping | Find output programs | Set 4

    C ++循环| 查找输出程序| 套装4

  • C++ Looping | Find output programs | Set 5

    C ++循环| 查找输出程序| 套装5

翻译自: https://www.includehelp.com/cpp-tutorial/switch-statements-find-output-programs-set-1.aspx

小程序 || 语句

小程序 || 语句_C ++开关语句| 查找输出程序| 套装1相关推荐

  1. g++默认参数_C ++默认参数| 查找输出程序| 套装2

    g++默认参数 Program 1: 程序1: #include <iostream> using namespace std; int K = 10; int fun() { retur ...

  2. g++默认参数_C ++默认参数| 查找输出程序| 套装1

    g++默认参数 Program 1: 程序1: #include <iostream> using namespace std; int sum(int X, int Y = 20, in ...

  3. c语言指针++_C ++此指针| 查找输出程序| 套装1

    c语言指针++ Program 1: 程序1: #include <iostream> using namespace std; int main() { int A = 10; this ...

  4. c ++查找字符串_C ++朋友功能| 查找输出程序| 套装1

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { int A, B; fr ...

  5. c ++查找字符串_C ++朋友功能| 查找输出程序| 套装2

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample1 { int A, B; f ...

  6. c语言指针++_C ++此指针| 查找输出程序| 套装3

    c语言指针++ Program 1: 程序1: #include <iostream> using namespace std; class Test { int VAL; public: ...

  7. 输入输出数组元素的函数重载_C ++函数重载| 查找输出程序| 套装3

    输入输出数组元素的函数重载 Program 1: 程序1: #include <iostream> using namespace std; class Test { public: vo ...

  8. c++重载++运算符_C ++运算符重载| 查找输出程序| 套装3

    c++重载++运算符 Program 1: 程序1: #include <iostream> using namespace std; class Test { public: int A ...

  9. 小程序 || 语句_C ++条件语句| 查找输出程序| 套装2

    小程序 || 语句 Program 1: 程序1: #include <iostream> #include <stdio.h> using namespace std; in ...

最新文章

  1. Transformer再下一城!low-level多个任务榜首被占领,北大华为等联合提出预训练模型IPT
  2. 一行代码搞定Python逐行内存消耗分析
  3. android studio新建layout,【Android Studio安装部署系列】十六、Android studio在layout目录下新建子目录...
  4. linux中make的用法
  5. TEA、XTEA、XXTEA加密解密算法
  6. SpringBoot+Vue 完整的外卖系统,手机端和后台管理
  7. eclipse新建服务器项目,使用eclipse快速新建spirngboot项目的方法
  8. OSI参考模型(2)
  9. java web中的相对路径和绝对路径
  10. Jzoj3883 线段树
  11. 第四课曲面与曲线方程
  12. 随机无梯度Frank-Wolfe方法的统一分析
  13. SUMO交通仿真-核心概念和基础知识速览
  14. Discuz模板制作教程
  15. IPD数字诀(一二三四五六七八九十)
  16. 没学编程的孩子,和从小学编程的孩子,差距有多大?
  17. Excel如何条件求和
  18. 笔记本电脑如何锁定计算机,笔记本电脑怎么锁定关闭触摸板
  19. 典型相关分析 python_CCA典型关联分析原理与Python案例
  20. Hank的无线802.11学习笔记--part 5

热门文章

  1. html频谱跳动效果,HTML5音频可视化频谱跳动代码
  2. [2020-CVPR] Dynamic Region-Aware Convolution 论文简析
  3. python灰色关联度分析代码_灰色关联分析法步骤 - osc_uwnmtz9n的个人空间 - OSCHINA - 中文开源技术交流社区...
  4. 谷歌浏览器中文版_中国科学家设计超薄指尖传感器,厚度不到A4纸五分之一 / 谷歌发布地图时光机:百年前,你家街道啥样?/ AI看图说话首超人类...
  5. python程序设计上机实践第三章答案_20192419 实验三《Python程序设计》实验报告
  6. 就业技术书文件表格_公路工程全套资料—开工施工检验等表格范本,及监理内业常用资料...
  7. Oracle GoldenGate经典架构
  8. Part 2: Containers
  9. pythonchallenge_level2
  10. 中美共建大数据创新研究中心