(Model Paper) C++ Language Basic Knowledge Model Paper

C++ Language Basic Knowledge Model Paper

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?
a) 0
b) a.out
c) 2
d) 3
e) 7
f) Other
g) I don't know

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;
}
a) Compiler error
b) wow
c) bab
d) heh
e) Undefined behaviour
f) I don't know

3) Which header file you should include for C++ file I/O?
a) fileio
b) ifstream
c) iostream
d) fstream
e) Other
f) I don't know

4) What is the default access permission for members in a class?
a) public
b) private
c) protected
d) I don't know

5) What is the default access permission for members in a struct?
a) public
b) private
c) protected
d) 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);
a) 5
b) 4
c) 6
d) Compiler error
e) Undefined behaviour
f) I don't know

7.What will !((1 || 0) && 0) evaluate to?
a) 1
b) 0
c) Wrong code
d) I don't know

8. If i = 5, what will be the result of:
do {
cout << (--i)-- << " ";
} while(i>=2 && i < 5);
a) Compiler error
b) It won't enter the loop
c) It will loop forever
d) 4 3 2 1
e) 4 3 2
f) 4 2 1
g) 4 2
h) I don't know

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 << " ";
}
a) 0 1 2
b) 0 7 1 7 2 7
c) 0 7 5 1 7 5 2 7 5
d) None of these
e) I don't know

10. What will be printed on the screen after running:
int x=65, *p = &x;
cout << p << "__" << *p ;
a) Compiler error
b) Program will crash
c) MemoryAddress_65
d) 65_MemoryAddress
e) Other
f) I don't know

11. In which header file is the function isalpha()?
a) conio.h
b) ifstream.h
c) string.h
d) cctype.h
e) Other
f) I don't know

12. Which one is correct?
a) int a; a = new int[20];
b) int a; a = new int(20);
c) int *a; a = new int[20];
d) int *a; a = new 20;
e) int *a; a = new sizeof(int*20);
f) int a; a = new sizeof(int*20);
g) I don't know

13. How do you access the last cell of "int arr[123];"?
a) arr[123]...
b) arr[124]...
c) arr[122]...
d) Other
e) I don't know

14. May the main() function be overloaded?
a) Yes
b) No
c) 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);
a) Program will freeze
b) 0
c) 6
d) 10
e) 12
f) Other
g) I don't know

16. If Foo is a member function of a class, which of the following uses of const is legal?
a) void Foo(const Squid& a);
b) void Foo(Squid& a) const;
c) void Foo(const Squid& a) const;
d) const void Foo(const Squid& a) const;
e) All of the above
f) None of the above
g) I don't know

17. If Foo is a static function in a class, which of the following uses of const is legal?
a) void Foo(Squid& const a);
b) void const Foo(Squid& a);
c) void Foo(const Squid& a);
d) void (Squid& a) const;
e) I don't know

18. Is it possible that a class does not have a name?
a) Yes, but you can't have objects from it
b) Yes, and you can have objects from it
c) No
d) 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"?
a) Hello World
b) Hello Wo
c) Hello W
d) Hello
e) Other
f) I don't know

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; }
};
And we create an object from class B, what will be the result?
a) 3124
b) 3142
c) 3412
d) 1234
e) 1324
f) 1342
g) Other
h) I don't know

21. What will be the result of: cout << (5 << 3); ?
a) Compiler error
b) 53
c) 40
d) 35
e) I don't know

22. What will be the result of: cout << 22/5*3; ?
a) 13.2
b) 1.47
c) 12
d) 1
e) Other
f) I don't know

23. Which keyword specifies that an integer variable can not take negative values?
a) positive
b) long
c) unsigned
d) Other
e) There is not such a keyword
f) I don't know

24. If we have: char a; , which one is incorrect?
a) a = 3;
b) a = "3";
c) a = '3';
d) All are correct
e) I don't know

25. What will happen if we have this code:
char a[3] = {'d','w','\0'};
char b[3];
b = a;
a) "b" will be the same as "a"
b) "b" will be unchanged
c) Compiler error
d) Other
e) I don't know

26. Is this code legal: int a; int b[a]; ?
a) Yes
b) No
c) I don't know

27. If we have:
int a=9; //in the global space...
void f() { int a; a = 4; }
And if we type: cout << a; in the main() function, what will be the result?
a) 9
b) 0
c) 4
d) Other
e) I don't know

28. If we have this code:
class A { public: int a; };
A *obj;

How do we access the "a" variable?
a) obj.a
b) obj-a
c) obj->a
d) obj::a
e) I don't know

29. Which of these has the highest precedence?
a) ++
b) ()
c) *
d) /
e) +
f) I don't know

30.What should you do to free the memory after running this code?
char *a; a = new char[20];
a) delete [] a;
b) delete a[];
c) delete a;
d) I don't know