C++ Variables and Data Types

This quiz tests your knowledge of basic C++ variables and data types. It contains 10 MCQs

Last Updated :
Discuss
Comments

Question 1

What will be the output of the following code?

C++
#include<iostream>
using namespace std;
int main ()
{
int cin;
cin >> cin;
cout << "cin" << cin;
return 0;
}
  •  error in using cin keyword

  • cin+junk value

  •  cin+input

  • Runtime error


     

Question 2

#include <iostream>
using namespace std;
int main()
{
float f = 3.5;


int b = static_cast<int>(f);


cout << b;
}

  • 4

  • 3

  • 5

  • 2

Question 3

Which of the following types is the language C++?

  • Procedural

  • Dynamically typed language
     

  • Statically typed language

  • All of the above

Question 4

#include<iostream>
using namespace std;


class Test
{
private:
static int count;
public:
Test& fun();
};


int Test::count = 0;


Test& Test::fun()
{
Test::count++;
cout << Test::count << " ";
return *this;
}


int main()
{
Test t;
t.fun().fun().fun().fun();
return 0;
}

  • Compiler Error

  • 4 4 4 4

  • 1 1 1 1


     

  • 1 2 3 4

Question 5

Why do we use the “dynamic_cast” type conversion in c++?


 

  • result of the type conversion is a valid

  •  to be used in low memory

  • result of the type conversion is an invalid


     

  •  it is used for storage

Question 6

#include<iostream>
using namespace std;
int x = 1;
void fun()
{
int x = 2;
{
int x = 3;
cout << ::x << endl;
}
}
int main()
{
fun();
return 0;
}
  • 0

  • 1

  • 2

  • 3

Question 7

In C++, const qualifier can be applied to

1) Member functions of a class

2) Function arguments

3) To a class data member which is declared as static

4) Reference variables


 

  • Only 1, 2 and 3

  • Only 1, 2 and 4

  • Only 1, 3 and 4


     

  • All

Question 8

Which of the following is true?

  • Static methods cannot be overloaded

  • Static data members can only be accessed by static methods.

  • Non-static data members can be accessed by static methods.

  • Static methods can only access static members (data and methods) 

Question 9

How are the constants declared?

  • const keyword

  • #define preprocessor

  •  both a and b

  • None of these

Question 10

Which of the following is not a correct variable in C++?

  • VARIABLE_1234

  • _varname

  • VARNAME

  •  7var_name

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion