Let's Have Some Fun ^_^

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Mostafa Yaseer
M
Mostafa Yaseer
Community Contributor
Quizzes Created: 1 | Total Attempts: 103
Questions: 10 | Attempts: 103

SettingsSettingsSettings
Lets Have Some Fun ^_^ - Quiz


Questions and Answers
  • 1. 

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

    • A.

      1010

    • B.

      10 10

    Correct Answer
    B. 10 10
    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.

    Rate this question:

  • 2. 

    Int main(){ int x = 10; int y = 5; ________{ cout << "x is greater than y"; return 0; }

    Correct Answer
    if(x > y),if( x > y),if(x>y)
    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; }

    • A.

      10

    • B.

      Compile Error

    • C.

      20

    • D.

      Run time Error

    Correct Answer
    C. 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?

    • A.

      Float

    • B.

      Real

    • C.

      Double

    • D.

      String

    Correct Answer
    B. 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)

    • A.

      /*comment/*

    • B.

      // comment

    • C.

      {comment}

    • D.

      /*comment*/

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

    • A.

      :=

    • B.

      =

    • C.

      ==

    • D.

      Equals

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

    • A.

      10 11 12

    • B.

      1011 12

    • C.

      101112

    • D.

      Compile Error

    Correct Answer
    D. 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; }

    • A.

      Compile Error

    • B.

      Run time Error

    • C.

      Hello

    • D.

      World

    Correct Answer
    C. 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; }

    • A.

      10 11 17.5

    • B.

      10 12 15

    • C.

      11 12 17

    • D.

      11 11 16  

    Correct Answer
    D. 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; }

    • A.

      1 0

    • B.

      1 1

    • C.

      True false

    • D.

      0 0

    • E.

      False true

    • F.

      False  false

    • G.

      Compiler Error

    Correct Answer
    D. 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 +

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.