Let's Have Some Fun ^_^

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Mostafa Yaseer
M
Mostafa Yaseer
Community Contributor
Quizzes Created: 1 | Total Attempts: 104
| Attempts: 104 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. Int main(){ int x = 10; int y = 5; _____{ cout << "x is greater than y"; return 0; }

Explanation

The correct answer is "if(x > y),if( x > y),if(x>y)". This is because the code is checking if the value of x is greater than the value of y, and if it is, it will print "x is greater than y". The if statement is used to conditionally execute a block of code if the specified condition is true. In this case, there are three if statements, each checking the same condition, so the code will print the message three times if x is indeed greater than y.

Submit
Please wait...
About This Quiz
Lets Have Some Fun ^_^ - Quiz

A fun and engaging quiz designed to test knowledge of C++ programming basics, including syntax, control structures, and output operations.

2. What is the output of the following program? int x = 10 int main(){ int y = x; cout << y << endl

Explanation

The program declares a variable x and assigns it the value 10. In the main function, a variable y is declared and assigned the value of x. Then, the value of y is printed to the console. Since y is assigned the value of x, which is 10, the output will be 10.

Submit
3. Which of the following is not a correct variable type?

Explanation

The variable type "real" is not a correct variable type. In most programming languages, "real" is not recognized as a valid variable type. The correct variable types in this list are "float", "double", and "string". "Float" and "double" are used to represent decimal numbers, while "string" is used to represent a sequence of characters.

Submit
4. What is the output of the following program? int main(){ cout >> 10 << 11 <<endl;

Explanation

The given program will result in a compile error. This is because the "

Submit
5. Which of the following is the correct operator to compare two variables?

Explanation

The correct operator to compare two variables is ==. This operator checks if the values of the two variables are equal. The = operator is used for assignment, not comparison. The := operator is not a valid comparison operator in most programming languages. The word "equals" is not a valid operator in programming, it is used in some programming languages as a method or function to compare values.

Submit
6. What is the output of the following program? int x = 10; int main(){ int x = 20; cout << x; return 0; }

Explanation

The output of the program is 20 because the variable x is redefined inside the main function with a value of 20. When the program executes the line "cout

Submit
7. What is the output of the following question if the input is 0? int main(){ int x; cin >> x; if(!x){ cout << "hello"; } else{ cout << "world"; } return 0; }

Explanation

The code snippet asks for user input and stores it in the variable "x". If the value of "x" is 0, the condition "!x" will evaluate to true and the program will output "hello". Therefore, the output of the program when the input is 0 is "hello".

Submit
8. Which of the following could be a comment? (check all the apply)

Explanation

The correct answer is "// comment" and "/*comment*/" because both of these options are written in the correct format for a comment in programming languages. The "//" indicates a single-line comment, while "/* */" indicates a multi-line comment. The other options, "{comment}" and "/*comment/*", do not follow the correct syntax for comments and are therefore not valid comments.

Submit
9. What is the output of the following program? int main() {     bool x = -1;      x++;      if (x)      {          x = x % 3;          cout<<(x > ++x)<<endl;      }      else         cout<<x++<<endl; x = x++;        cout<<(x < x++)<<endl;                                return 0; }

Explanation

The program initializes a boolean variable x with the value -1, which is equivalent to true in C++. Then, it increments x by 1 using the post-increment operator. Since the value of x is now 0, the program enters the else block and prints the value of x (0) followed by a line break. After that, x is incremented again using the post-increment operator, but the value of x is still 0. Therefore, the expression (x

Submit
10. What is the output of the following program? int main(){ int x = 10; int y = x++; int z = ++y + (x/2); cout << x << endl; cout << y << endl; ​​​​​​​cout << z << endl; return 0; }

Explanation

The program starts by initializing the variable x to 10. Then, the variable y is assigned the value of x, which is 10, and then x is incremented by 1 using the post-increment operator. So, after this step, x becomes 11 and y becomes 10.

Next, the variable z is assigned the value of y, which is 10, incremented by 1 using the pre-increment operator, which makes y equal to 11. Then, z is added to the result of x divided by 2, which is 5. So, z becomes 11 + 5 = 16.

Finally, the program prints the values of x, y, and z, which are 11, 11, and 16 respectively.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 19, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 19, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 23, 2019
    Quiz Created by
    Mostafa Yaseer
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Int main(){ ...
What is the output of the following program? ...
Which of the following is not a correct variable type?
What is the output of the following program?...
Which of the following is the correct operator to compare two...
What is the output of the following program? ...
What is the output of the following question if the input is 0? ...
Which of the following could be a comment? (check all the apply)
What is the output of the following program?...
What is the output of the following program? ...
Alert!

Advertisement