What is the output of the following code fragment? string str1 = "hello"; string str2 = "Hello"; string out; if(str1==str2) { out = "First"; } if(str1!=str2) { out = "Second"; } else if(str1 <= str2 || str1 != str2) { out = "Third"; } cout << out << endl; Group of answer choices First Second Third First and Second First and Third Second and Third None of the above ---------------------- Given the following code fragment, what is the final value of y? int x, y; x = -1; y = 0; while (x <= 3) { y += 2; x += 1; } Group of answer choices 2 6 10 8 --------- Given the following code segment, what is the final value of i that is output to the screen? int i; for (i = 0; i <= 8; ++i) { cout << "UNT! "; } cout << "i=" << i << endl; Group of answer choices i=9 i=8 i=7 None of these
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
What is the output of the following code fragment?
string str1 = "hello";
string str2 = "Hello";
string out;
if(str1==str2) {
out = "First";
}
if(str1!=str2) {
out = "Second";
}
else if(str1 <= str2 || str1 != str2) {
out = "Third";
}
cout << out << endl;
Given the following code fragment, what is the final value of y?
int x, y;
x = -1;
y = 0;
while (x <= 3)
{
y += 2;
x += 1;
}
Given the following code segment, what is the final value of i that is output to the screen?
int i;
for (i = 0; i <= 8; ++i)
{
cout << "UNT! ";
}
cout << "i=" << i << endl;
Step by step
Solved in 4 steps with 3 images