小程序 || 语句_C ++条件语句| 查找输出程序| 套装1
小程序 || 語句
Program 1:
程序1:
#include <iostream> using namespace std;int main() {if (NULL) {cout << "Hello World";}else {cout << "Hii World";}return 0; }Output:
輸出:
Hii WorldExplanation:
說明:
The program will print "Hii World" on the console screen. Because the value of NULL is 0, then the if statement will be false and the else part will be executed.
該程序將在控制臺屏幕上打印“ Hii World” 。 因為NULL的值為0 ,所以if語句將為false并將執行else部分。
Program 2:
程式2:
#include <iostream> using namespace std;int main() {int A = 5, B = 10, C = 20;if (A && B > C) {cout << "ABC";}else if (A = B || C == 20) {cout << "PQR";}else {cout << "XYZ";}return 0; }Output:
輸出:
PQRExplanation:
說明:
Execute the program step by step:
逐步執行程序:
int A=5, B=10, C=20;if(A&&B>C)if(5&&10>20)According to operator priority table, greater than (>) operator will evaluate before the logical and (&&) thenif(5&&0)if(0) Then, program's execution will jump to,else if(A=B || C==20)According to the operator priority table, equal to (==) operator will be evaluated before the assignment and logical or operatorelse if(10 || 20)else if(1)Here, condition is true and its block will be executed,Then the final output will be "PQR".Program 3:
程式3:
#include <iostream> using namespace std;int main() {int A = 15, B = 10, C = 20;if (A > B) {if (A >= 15) {if (C > 10 ? A > 5 ? NULL : 1 : 2) {cout << "111";}else {cout << "222";}}else {cout << "333";}}else {cout << "444";}return 0; }Output:
輸出:
222Explanation:
說明:
Execute the program step by step:
逐步執行程序:
int A=15, B=10, C=20;if( A>B) that is if(15>10) condition is true thenif(A>=15) that is if(15>=15) condition is true thenNow checking,if(C>10 ? A>5 ? NULL : 1 : 2) Here, C>10 that is 20>10 condition is true then check A>5 that is 15>5 condition is again true then it returns NULL, and the value of NULL is 0 and then if statement will be false. Then the else part will be executed and will print "222" on the console screen.Recommended posts
推薦的帖子
C++ Conditional Statements | Find output programs | Set 2
C ++條件語句| 查找輸出程序| 套裝2
C++ Reference Variable| Find output programs | Set 1
C ++參考變量| 查找輸出程序| 套裝1
C++ Reference Variable| 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++ Operators | Find output programs | Set 1
C ++運算符| 查找輸出程序| 套裝1
C++ Operators | Find output programs | Set 2
C ++運算符| 查找輸出程序| 套裝2
C++ Switch Statement | Find output programs | Set 1
C ++轉換語句| 查找輸出程序| 套裝1
C++ Switch Statement | 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/conditional-statements-find-output-programs-set-1.aspx
小程序 || 語句
總結
以上是生活随笔為你收集整理的小程序 || 语句_C ++条件语句| 查找输出程序| 套装1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 正则数字字母下划线至少两种_8085微处
- 下一篇: 死锁终结者:顺序锁和轮询锁!