Vidyalelo
C++ Programming · all questions

Variables and Data Types in C++
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

123

Questions

6/7

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
enum  cat 
{
    temp = 7
};
int main()
{
    int age = 14;
    age /= temp;
    cout << "If you were cat, you would be " << age << endl;
    return 0;
}

Select an option to see the answer and solution.

For what values of the expression is an if-statement block not executed?

Select an option to see the answer and solution.

Identify the incorrect statements.
int var = 10;
int *ptr = &(var + 1); //statement 1
int *ptr2 = &var; //statement 2
&&var = 40; //statement 3

Select an option to see the answer and solution.

Pick the right option.
Statement 1: Global values are not initialized by the stream.
Statement 2: Local values are implicitly initialised to 0.

Select an option to see the answer and solution.

Can two functions declare variables(non static) with the same name?

Select an option to see the answer and solution.

Is the size of character literals different in C and C++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
    void a = 10, b = 10;
    int c;
    c = a + b;
    cout << c;
    return 0;
}

Select an option to see the answer and solution.

Which is correct with respect to the size of the data types?

Select an option to see the answer and solution.

Which of the following is not one of the sizes of the floating point types?

Select an option to see the answer and solution.

. . . . . . . . have the return type void.

Select an option to see the answer and solution.

Which of these expressions will make the rightmost set bit zero in an input integer x?

Select an option to see the answer and solution.

Which of the following is a valid floating-point literal?

Select an option to see the answer and solution.

Identify the type of variables.
typedef char* CHAR;
CHAR p,q;

Select an option to see the answer and solution.

Given the variables p, q are of char type and r, s, t are of int type. Select the right statement?
 1. t = (r * s) / (r + s);
2. t = (p * q) / (r + s);

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
    float f1 = 0.5;
    double f2 = 0.5;
    if (f1 == 0.5f)
        cout << "equal";
    else
        cout << "not equal";
    return 0;
}

Select an option to see the answer and solution.

To which of these enumerators can be assigned?

Select an option to see the answer and solution.

Pick the right option.
Statement 1: A definition is also a declaration.
Statement 2: An identifier can be declared just once.

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int g = 100;
int main()
{
    int a;
    {
        int b;
        b = 20;
        a = 35;
        g = 65;
        cout << b << a << g;
    }
    a = 50;
    cout << a << g;
    return 0;
}

Select an option to see the answer and solution.

Identify the user-defined types from the following?

Select an option to see the answer and solution.

Identify the incorrect option.

Select an option to see the answer and solution.