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

小程序 || 语句

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

小程序 || 语句

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542239.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python爬虫与django_请问django和爬虫程序如何整合?

Django 模型是与数据库相关的&#xff0c;与数据库相关的代码一般写在 models.py 中&#xff0c;Django 支持 sqlite3, MySQL, PostgreSQL等数据库&#xff0c;只需要在settings.py中配置即可&#xff0c;不用更改models.py中的代码&#xff0c;丰富的API极大的方便了使用。本节…

Spark的枚举类型实例!scala的枚举。

Spark的枚举类型实例&#xff01;scala的枚举。Enumeration定义&#xff1a;[deploy] SparkSubmitAction { Value Value }Enumeration使用&#xff1a;appArgs. {SparkSubmitAction.> (appArgs)SparkSubmitAction.> (appArgs)SparkSubmitAction.> (appArgs) }转载于:…

c ++查找字符串_C ++类和对象| 查找输出程序| 套装5

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>using namespace std;class Sample {int X;int* PTR &X;public:void set(int x) const;void print();};void Sample::set(int x) const{*PTR x;}void Sample::print(){cout << *PTR - EOF <…

mysql8和5.7区别_mysql8.0与mysql5.7安全加密小差别

今天升级到了mysql8.0 做主从同步遇到下面问题2020-07-21T14:09:52.626718Z 13 [ERROR] [MY-010584] [Repl] Slave I/O for channel : error connecting to master slave_replication172.20.0.2:3306 - retry-time: 60 retries: 1 message: Authentication plugin caching_sha2…

c ++查找字符串_C ++类和对象| 查找输出程序| 套装3

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>using namespace std;class Sample {int X;public:void set(int x){X x;}void print(){cout << X << " ";}} A, B;int main(){A.set(10);B.set(20);A.print();B.print();return 0;…

时间轮

老早之前就听说时间轮算法特别高效&#xff0c;Linux内核都用的它&#xff0c;这两天抽空实现了遍……嗯&#xff0c;被差一bug搞死(~&#xffe3;▽&#xffe3;~) 啊哈 网上扣来的图&#xff0c;原理好懂&#xff1a;轮子里的每格代表一小段时间&#xff08;精度&#xff09;…

qc35 说明书_使用Bose QC35 2年的心得 | 迟而不迟的深度体验 | 文附佩戴效果照片...

小编注&#xff1a;此篇文章来自即可瓜分10万金币&#xff0c;周边好礼达标就有&#xff0c;邀新任务奖励无上限&#xff0c;点击查看活动详情创作立场声明&#xff1a;本文所测商品为自费购入&#xff0c;我会在文中点明。坚持来自内心的主观评测是起码的底线&#xff0c;不会…

threadgroup_Java ThreadGroup类的checkAccess()方法和示例

threadgroupThreadGroup类的checkAccess()方法 (ThreadGroup class checkAccess() method) checkAccess() method is available in java.lang package. checkAccess()方法在java.lang包中可用。 checkAccess() method is used to check whether the currently running thread h…

qt tab弹出特效_Nuke Studio 12(影视特效合成软件)中文版分享

Nuke 12是一款功能强大&#xff0c;世界知名的影视后期特效合成软件。NUKE是一个获得学院奖(Academy Award)的数码合成软件。已经经过10年的历练&#xff0c;为艺术家们提供了创造具有高质素的相片效果的图像的方法。NUKE无需专门的硬件平台&#xff0c;但却能为艺术家提供组合…

c ++ 链表_C ++程序查找两个单个链表的并集

c 链表Problem statement: Write a C program to find the union of two single linked lists. 问题陈述&#xff1a;编写一个C 程序来查找两个单个链表的并集。 Example: 例&#xff1a; Let the first linked list be:5->4->3->6->1->NULLLet the second l…

精华版线段树模板

哈哈哈&#xff0c;打了一上午。。。#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; ll a[10000010]; ll lazy[1000000]; …

【转】unity地形插件T4M使用帮助

unity的地形系统在手机游戏中因为效率问题基本无法使用&#xff0c;只能通过T4M这个地形插件来进行优化制作。下面大概讲解一下使用流程及方法。 先中U3D里面用自带的地形系统刷出想要的地形和贴图。贴图可以大概刷一下。后面要重新刷。 用导出脚本ExportTerrain.js导出地形为O…

ansys添加力矩_ANSYS软件中施加扭矩的方法

ANSYS软件中施加扭矩的方法胡意立&#xff0c;孙明礼&#xff0c;沈燕青&#xff0c;周佳杰&#xff0c;胡林强【摘要】在机械结构的有限元分析中&#xff0c;常会遇到施加扭矩的问题。文中探讨了在ANSYS软件中施加扭矩的一种方法&#xff0c;以在一个六棱柱一端施加扭矩为实例…

Python | 程序从列表中删除重复的元素

Example: 例&#xff1a; Input:list1: [10, 20, 10, 20, 30, 40, 30, 50]Output:List after removing duplicate elementslist2: [10, 20, 30, 40, 50]Logic: 逻辑&#xff1a; To implement the program is too easy, we have to append elements one by one to another…

Linux的简介与虚拟机的管理

Linux的简介&#xff1a; 严格的来讲&#xff0c;Linux不算是一个操作系统&#xff0c;只是一个Linux系统中的内核&#xff0c;Linux的全称是GUN/Linux&#xff0c;这才算是一个真正意义上的Linux系统。 Linux是一个多用户多任务的操作系统&#xff0c;拥有良好的用户界面&…

python递归查找_Python程序使用递归查找数字的幂

python递归查找Given the base x and the power y and we have to find the x to the power y using recursion in Python. 给定基数x和幂y &#xff0c;我们必须使用Python中的递归找到x到幂y 。 By using recursion – We will be multiplying a number (initially with val…

phalapi可以依赖注入么_PHP 依赖注入

通常调用一个类里面的方法需要如何操作&#xff1a;$class new class();$class->fun()依赖注入模式用来减少程序间的耦合依赖注入共有三种模式&#xff1a;setter 方法注入着重说下setter方法注入并结合ArrayAccess/*** Class Di* property People*/class Di implements Ar…

R语言:ggplot2精细化绘图——以实用商业化图表绘图为例(转)

本文旨在介绍R语言中ggplot2包的一些精细化操作&#xff0c;主要适用于对R画图有一定了解&#xff0c;需要更精细化作图的人&#xff0c;尤其是那些刚从excel转ggplot2的各位&#xff0c;有比较频繁的作图需求的人。不讨论那些样式非常酷炫的图表&#xff0c;以实用的商业化图表…

Linux中常用的命令

1.文件建立 touch file&#xff08;文件的名字&#xff09; 注意&#xff1a; touch不但可以建立文件也可以修改文件的时间戳 时间戳分为&#xff1a; atime&#xff1a;文件内容被访问的时间标识 mtime&#xff1a;文件内容被修改的时间标识 ctime&#xff1a;文件属性或文件内…

蓝桥杯宝藏排序题目算法(冒泡、选择、插入)

冒泡排序: def bubble_sort(li): # 函数方式for i in range(len(li)-1):exchangeFalsefor j in range(len(li)-i-1):if li[j]>li[j1]:li[j],li[j1]li[j1],li[j]exchangeTrueif not exchange:return 选择排序: 从左往右找到最小的元素&#xff0c;放在起始位置…