小程序 || 語句_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.pswp.cn/news/542239.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542239.shtml
英文地址,請注明出處:http://en.pswp.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;放在起始位置…