Question 1
What will be the output?
class Test {
int x;
};
int main()
{
Test t;
cout << t.x;
return 0;
}
0
Garbage Value
Compiler Error
None of the Above
Question 2
What does the this pointer in C++ represent?
Pointer to class name
Pointer to current object
Pointer to base class
Pointer to constructor
Question 3
#include
using namespace std;
class Test
{
static int x;
int *ptr;
int y;
};
int main()
{
Test t;
cout << sizeof(t) << " ";
cout << sizeof(Test *);
}
Question 4
Which of the following is true about the following program
#include
class Test
{
public:
int i;
void get();
};
void Test::get()
{
std::cout << "Enter the value of i: ";
std::cin >> i;
}
Test t; // Global object
int main()
{
Test t; // local object
t.get();
std::cout << "value of i in local t: "<<t.i<<'\n';
::t.get();
std::cout << "value of i in global t: "<<::t.i<<'\n';
return 0;
}
Compiler Error: Cannot have two objects with same class name
Compiler Error in Line "::t.get();"
Compiles and runs fine
Runtime Error
Question 5
Question 6
What is the correct way to define a class in C++?
class MyClass { int x; void func(); }
class MyClass { public: int x; void func(); };
class MyClass { public: int x; void func(); }
class MyClass { public int x; void func(); };
Question 7
In C++, which operator is used to access a member function or variable from an object?
->
::
.
*
Question 8
Given the following class:
class A {
int x;
public:
A(int v) { x = v; }
int getX() { return x; }
};
What will A obj(5); cout << obj.getX(); print?
0
5
Compiler error
Garbage value
There are 8 questions to complete.