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

4/7

Page

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

What is the size of wchar_t in 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()
{
    int x = -1;
    unsigned int y = 2;
 
    if(x > y) 
    {
        cout << "x is greater";
    }
    else 
    {
	cout << "y is greater";
     }      
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void addprint()
{
    static int s = 1;
    s++;
    cout << s;
}
int main()
{
    addprint();
    addprint();
    addprint();
    return 0;
}

Select an option to see the answer and solution.

What is the value of p in the following C++ code?
#include <iostream>
using namespace std;
int main()
{
    int p;
    bool a = true;
    bool b = false;
    int x = 10;
    int y = 5;
    p = ((x | y) + (a + b));
    cout << p;
    return 0;
}

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 f(int p, int q)
{
    if (p > q)
        return p;
    else
        return q;
}
main()
{
    int a = 5, b = 10;
    int k;
    bool x = true;
    bool y = f(a, b);
    k =((a * b) + (x + y));
    cout << k;
}

Select an option to see the answer and solution.

Which of these expressions will return true if the input integer v is a power of two?

Select an option to see the answer and solution.

What constant defined in <climits> header returns the number of bits in a char?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h>
int main()
{
    char a = '\012';
 
    printf("%d", a);
    return 0;
}

Select an option to see the answer and solution.

What will happen when defining the enumerated type?

Select an option to see the answer and solution.

When a language has the capability to produce new data type mean, it can be called as

Select an option to see the answer and solution.

Which of the given statements are false
i. extern int func;
ii. extern int func2(int,int);
iii. int func2(int,int);
iv. extern class foo;

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()
{
    int i = 3;
    int l = i / -2;
    int k = i % -2;
    cout << l << k;
    return 0;
}

Select an option to see the answer and solution.

What does the following statement mean?
void a;

Select an option to see the answer and solution.

What is the value of the following 8-bit integer after all statements are executed?
int x = 1;
x = x << 7;
x = x >> 7;

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()
{
    int num = 0x20 + 020 + 20;
    cout << sizeof(num)<<'\n';
    return 0;
}

Select an option to see the answer and solution.

Which of the following will not return a value?

Select an option to see the answer and solution.

Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return?

Select an option to see the answer and solution.

Is bool a fundamental data type in 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()
{
    int a = 8;
    cout << "ANDing integer 'a' with 'true' :" << (a && true);
    return 0;
}

Select an option to see the answer and solution.

Which data type is used to represent the absence of parameters?

Select an option to see the answer and solution.