V.Vidhya Logo

V.Vidhya

Variables & User I/O


Q1.

What will be the output of the following program?

You have to predict the output yourself without running/executing the code.

#include <iostream>

int main()
{
    std::cout << "Hello, કેમ છો?\n";

    return 0;
}
  1. Hello,
  2. “Hello, કેમ છો?\n”
  3. Hello, કેમ છો?
  4. Hello, how are you?

Q2.

Write a program that asks the user to enter an integer number and then enter a second integer number. The program should tell the user what the result of adding and subtracting those two numbers is.

Expected Output:

Enter the first integer number: 6   // user input
Enter the second integer number: 4   // user input

6 + 4 = 10
6 - 4 = 2

Q3.

Based on how you should name a variable, indicate whether each variable name mentioned below is conventional (follows best practices), unconventional (compiler will accept but does not follow best practices), or invalid (will not compile), and why.

  1. int sum;
  2. int _apples;
  3. int VALUE;
  4. int my variable name;
  5. int TotalCustomers;
  6. int void;
  7. int numFruit;
  8. int 3subject;
  9. int meters_of_pipe;

Q4.

What will be the output of the following program when run multiple times?

#include <iostream>

int main()
{
    int x;
    
    std::cout << x << '\n';

    return 0;
}

You have to predict the output yourself without running/executing the code.

  1. always 0
  2. always -1
  3. any random garbage value but consistently
  4. undefined

Q5.

Write a program that takes an integer number from user and then prints the doubled and tripled value of that number.

Expected Output:

Enter an integer: 4   // user input

Double of 4: 8
Triple of 4: 12

Q6.

What will be the output of the following programs?

You have to predict the output yourself without running/executing the code.


Q7.

Write a program that asks the user to enter three integer values and then print the average of these values.

Expected Output:

Enter three numbers: 3 9 24   // user input

The average of 3, 9 and 24 is 12.

Next Post
Data Types