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
SettingsSettings
Please wait...
  • 1/10 Questions

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

    • 1010
    • 10 10
Please wait...
About This Quiz

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

Lets Have Some Fun ^_^ - Quiz

Quiz Preview

  • 2. 

    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.

    Rate this question:

  • 3. 

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

    • 10

    • Compile Error

    • 20

    • Run time Error

    Correct Answer
    A. 20
    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

    Rate this question:

  • 4. 

    Which of the following is not a correct variable type?

    • Float

    • Real

    • Double

    • String

    Correct Answer
    A. Real
    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.

    Rate this question:

  • 5. 

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

    • /*comment/*

    • // comment

    • {comment}

    • /*comment*/

    Correct Answer(s)
    A. // comment
    A. /*comment*/
    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.

    Rate this question:

  • 6. 

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

    • :=

    • =

    • ==

    • Equals

    Correct Answer
    A. ==
    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.

    Rate this question:

  • 7. 

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

    • 10 11 12

    • 1011 12

    • 101112

    • Compile Error

    Correct Answer
    A. Compile Error
    Explanation
    The given program will result in a compile error. This is because the "

    Rate this question:

  • 8. 

    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; }

    • Compile Error

    • Run time Error

    • Hello

    • World

    Correct Answer
    A. Hello
    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".

    Rate this question:

  • 9. 

    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; }

    • 10 11 17.5

    • 10 12 15

    • 11 12 17

    • 11 11 16  

    Correct Answer
    A. 11 11 16  
    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.

    Rate this question:

  • 10. 

    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; }

    • 1 0

    • 1 1

    • True false

    • 0 0

    • False true

    • False  false

    • Compiler Error

    Correct Answer
    A. 0 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 < x++) evaluates to false. The program prints false followed by a line break. Hence, the output of the program is 0 followed by a line break, and then false followed by a line break.

    Rate this question:

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.