1.If you have “int main(int argc, char* argv[])” and invoke your program this way: prog.exe a.out -i 2 -g -x 3 4 What will be the value of argc?

  • Other
  • I don’t know
  • a.out
  • 7
  • 3
  • 2
  • 0

2.If n=3, what will be the result of:

switch(n)
{
case '3':
cout << "wow \n";
break;
case 3:
cout << "bab \n";
break;
default:
cout << "heh \n";
break;
}

  • wow
  • Undefined behaviour
  • I don’t know
  • heh
  • Compiler error
  • bab

3.Which header file you should include for C++ file I/O?

  • Other
  • iostream
  • ifstream
  • I don’t know
  • fstream
  • fileio

4.What is the default access permission for members in a class?

  • public
  • protected
  • private
  • I don’t know

5.What is the default access permission for members in a struct?

  • public
  • protected
  • private
  • I don’t know

6.What will be the result of:

int f(int a) { return ++a; }
int f(unsigned int a) { return --a; }
cout << f(5);

  • Undefined behaviour
  • I don’t know
  • Compiler error
  • 6
  • 5
  • 4

7.What will !((1 || 0) && 0) evaluate to?

  • Wrong code
  • Undefined behaviour
  • I don’t know
  • 1
  • 0

8.If i = 5, what will be the result of:

do
{
cout << (--i)-- << " ";
} while(i>=2 && i < 5);

  • It won’t enter the loop

  • It will loop forever
  • I don’t know
  • Compiler error
  • 4 3 2 1
  • 4 3 2
  • 4 2 1
  • 4 2

9.What will be the result after running this code:

for(int i=0;i<3;i++)
{
cout << i << " ";
continue;
cout << 7 << " ";
break;
for(int j=0;j<1;j++)
cout << 5 << " ";
}

  • None of these
  • I don’t know
  • 0 7 5 1 7 5 2 7 5
  • 0 7 1 7 2 7
  • 0 1 2

10.What will be printed on the screen after running:

int x=65, *p = &x;
cout << p << "__" << *p ;

  • Program will crash

  • Other
  • MemoryAddress_65
  • I don’t know
  • Compiler error
  • 65_MemoryAddress

11.In which header file is the function isalpha()?

  • string.h
  • Other
  • ifstream.h
  • I don’t know
  • ctype.h
  • conio.h

12.Which one is correct?

  • int a; a = new sizeof(int*20);
  • int a; a = new int[20];
  • int a; a = new int(20);
  • int *a; a = new sizeof(int*20);
  • int *a; a = new int[20];
  • int *a; a = new 20;
  • I don’t know

13.How do you access the last cell of “int arr[123];”?

  • Other
  • I don’t know
  • arr[124]…
  • arr[123]…
  • arr[122]…

14.May the main() function be overloaded?

  • Yes
  • No
  • I don’t know

15.If we have:

int f(int x)
{
if(x>2)
return x + f(--x);
else
return 0;
}

What will be the resulf of: cout << f(5);

  • Program will freeze
  • Other
  • I don’t know
  • 6
  • 12
  • 10
  • 0

16.If Foo is a member function of a class, which of the following uses of const is legal?

  • void Foo(Squid& a) const;
  • void Foo(const Squid& a);
  • void Foo(const Squid& a) const;
  • None of the above
  • const void Foo(const Squid& a) const;
  • All of the above
  • I don’t know

17.If Foo is a static function in a class, which of the following uses of const is legal?

  • void Foo(Squid& const a);
  • void Foo(const Squid& a);
  • void const Foo(Squid& a);
  • void (Squid& a) const;
  • I don’t know

18.Is it possible that a class does not have a name?

  • Yes, but you can’t have objects from it
  • Yes, and you can have objects from it
  • No
  • I don’t know

19.If we have this code:

char arr[8];
cin >> arr;

And this text is entered: “Hello World”, what there will be in “arr”?

  • Other
  • I don’t know
  • Hello World
  • Hello Wo
  • Hello W
  • Hello

20.If we have this code:

class A
{
public:
A() { cout << 1; }
~A() { cout << 2; }
};
class B : public A
{
public:
B() { cout << 3; }
~B() { cout << 4; }
};

21.And we create an object from class B, what will be the result?

  • Other
  • I don’t know
  • 3412
  • 3142
  • 3124
  • 1342
  • 1324
  • 1234

22.What will be the result of: cout << (5 << 3); ?

  • I don’t know
  • Compiler error
  • 53
  • 40
  • 35

23.What will be the result of: cout << 22/5*3; ?

  • Other
  • I don’t know
  • 13.2
  • 12
  • 1.47
  • 1

24.Which keyword specifies that an integer variable can not take negative values?

  • unsigned
  • There is not such a keyword
  • positive
  • Other
  • long
  • I don’t know

25.If we have: char a; , which one is incorrect?

  • I don’t know
  • All are correct
  • a = 3;
  • a = ‘3′;
  • a = “3″;

26.What will happen if we have this code:

char a[3] = {’d',’w',’\0′};
char b[3];
b = a;

  • Other
  • I don’t know
  • Compiler error
  • “b” will be unchanged
  • “b” will be the same as “a”

27.Is this code legal?

int a; int b[a];

  • Yes
  • No
  • I don’t know

28.If we have:


int a=9; //in the global space...
void f() { int a; a = 4; }

29.And if we type: cout << a; in the main() function, what will be the result?

  • Other
  • I don’t know
  • 9
  • 4
  • 0

30.If we have this code:


class A { public: int a; };
A *obj;

How do we access the “a” variable?

  • obj::a

  • obj.a
  • obj-a
  • obj->a
  • I don’t know

31.Which of these has the highest precedence?

  • I don’t know
  • /
  • ++
  • +
  • *
  • ()

32.What should you do to free the memory after running this code?

char *a; a = new char[20];

  • I don’t know
  • delete [] a;
  • delete a[];
  • delete a;

Tags: , ,

One Response to “C++ Test 1”

  1. rithu says:

    where is the answers of these questions..??

Leave a Reply

You must be logged in to post a comment.