Do you know that? 3 in 10 spend less hours at work than their full time employed equivalent next

Contact Email: teammmrem@yahoo.com

<< All Upwork (oDesk) and Elance Tests << Elance test answers << IT & Programming category

Test answers for C 2016

(487 / 1) Last updated: January 22
Elance • IT & Programming
Questions and answers are regularly updated. Answered and not answered tests questions.

This helps getting job: Hundreds of (cover letter examples , interview questions , profile samples ) • Earn on Upwork (oDesk)
Job assistance: jobs popularityfreelance rates

Popular test answers: HTML, .Net, CSS, English, SEO, Photoshop, iOS, Java, Android, Ruby, Python, JavaScript

See all 6 tests answers updated

Find Upwork (oDesk) and Elance test answers on this website:



Collapse | Expand

487 Answered Test Questions:

1. Which of the following is not a predefined variable type?

Answers:

• float

• int

• real

2. What will be the output if the following program: #include<stdio.h> int main(){ int a,b; a= -3 - - 25; b= -5 - (- 29); printf("a= %d b=%d", a, b); return 0; }

Answers:

• a=22 b=24

• a=22 b=34

• a=28 b=24

• a=28 b=34

3. What is i after the following block of code is executed : int i; i = 10/5/2/1;

Answers:

• 5

• 0

• 1

• 4

4. In C, a block is defined by...

Answers:

• angle brackets

• tabulations

• tags

• curly braces

• indentation

5. Is C Object Oriented?

Answers:

• Yes

• No

6. int *a, b;  What is b ?

Answers:

• An int

• It does not compile

• An int *

7. which of these is not valid keyword?

Answers:

• var

• double

• int

• char

• float

8. Which of the following is the correct operator to compare two integer variables?

Answers:

• equal

• ==

• =

• :=

9. What is the only function all C programs must contain?

Answers:

• main()

• start()

• program()

10. Which of the following special symbols are allowed in a variable name?

Answers:

• _ (underscore)

• * (asterisk)

• - (hyphen)

• | (pipeline)

11. int i = 17 / 3; what is the value of i ?

Answers:

• 5

• 5.60

• 6

• 5.666666

• 6.0

12. In C language, && is a

Answers:

• Relational Operator

• None of them

• Logical operator

• Arithmetic Operator

13. What is the value of the variable x?  int x; x = 32 / 64;

Answers:

• Undefined

• 0.5

• 0

14. What does "int *p = malloc(2);" do?

Answers:

• It will crash your program (an int is four bytes long, not two).

• It will make p point to the number 2.

• Nothing, it will yield a type mismatch compiler error.

• It will make p point to an uninitialized two-byte piece of memory allocated from the heap.

15. A C variable can start with a digit as well a letter.

Answers:

• False

• True

16. What will be the output of:  #include <stdio.h>  void main() {     char a[6] = "Hello";     printf("%d", sizeof(a));    }

Answers:

• Compile time error

• Array not initialized correctly

• Program will not execute.

• 6

17. int tab[3] = {0,1,2}; int i = 0; tab[++i] == ?

Answers:

• 1

• 2

• 0

18. How can you make an infinite loop in C?

Answers:

• All answers are right.

• while(1) { }

• for(;;) { }

• loop: ... goto loop;

19. If we pass an array as an argument of a function, what exactly get passed?

Answers:

• Address of array

• All elements of an array

• a[0]th value of array

• a[last]th value of array

20. Which one is NOT a reserved keyword?

Answers:

• switch

• extern

• intern

• struct

• static

21. Function Overloading is not supported in C.

Answers:

• False

• True

22. #ifdef __APPLE__ # include <dir/x.h> #else # include <other_dir/x.h> #endif  What does it mean?

Answers:

• It will include dir/x.h if __APPLE__ is not defined, or other_dir/x.h, otherwise.

• It will define __APPLE__, include dir/x.h and next time will include other_dir/x.h

• It will include dir/x.h if __APPLE__ is defined, or other_dir/x.h, otherwise.

• It will define __APPLE__ and include dir/x.h

23. In C ...

Answers:

• Strings does not exists in C.

• Strings are surrounded with double quotes, and Character with single-quotes.

• Strings and chars can be surrounded with double quotes or single-quotes.

24. What will be the output of this Program?  #include <stdio.h>  struct Data{ 	char a; 	char *data; 	int value; }; main()  { 	printf("%d\n",sizeof(struct Data)); }

Answers:

• 3

• 6

• 12

• 9

• It depends on the compiler and the hardware architecture.

25. What are the different types of floating-point data in C ?

Answers:

• float, double

• double, long int, float

• short int, double, long int

• float, double, long double

26. Will this loop terminate? int x=10; while( x-- > 0 );

Answers:

• no

• It will not compile

• It will cause segfault

• yes

27. What is the value of p in int a,b,*p; p=&a; b=**p; printf("%d",p);

Answers:

• address of variable a

• value of variable b

• address of variable b

• value of variable a

28. How can you access the first element of an array called 'arr'?

Answers:

• arr[0]

• *arr

• (both of these)

29. What will be the output?  void main() {       int const*p=9;       printf("%d",++(*p)); }

Answers:

• 10

• Compiler Error

• 9

30. Which statement is true about double?

Answers:

• its size is 128 bits

• it's an alias of float

• it uses the GPU

• its size depends on the implementation

31. What will be the output of the following program: #include <stdio.h> void TestFunc(int *ptr)     {         int x = 65;         ptr = &x;         printf("%d ", *ptr);  }     int main()     {         int y = 56;   int *ptr = &y;         TestFunc(&y);         printf("%d ", *ptr);     }

Answers:

• 65 56

• 56 65

• 56 0000000000x1

• 65 0000000000x1

32. char* buf[100]; strcpy(buf, argv[1]);  Which security risk is this code vulnerable to?

Answers:

• Integer overflow

• Race condition

• Format string

• Heap overflow

• Stack overflow

33. What is the value of 1 & 2?

Answers:

• 3

• 1

• 0

• 2

34. With:  sizeof(char *) == 4  sizeof(char) == 1   What will sizeof(plop) for char plop[2][3] be?

Answers:

• 6

• 10

• 18

• 14

35. What is the output of the following code?  char * str1 = "abcd"; char * str2 = "xyz";   if( str1 < str2 )    printf( "1" );  else    printf( "2" );

Answers:

• 1

• 2

• Undefined

36. foo[4] is equivalent of :

Answers:

• *(&foo + 4)

• &(foo + 4)

• (*foo + 4)

• There is no equivalent using those notations

• *(foo + 4)

37. What will the following code print?  void *p = malloc(0); printf ("%d\n", p);

Answers:

• Unknown, it depends on what malloc will return.

• Nothing, it will give a runtime error.

• 0

• Nothing, it won't compile.

38. To send an array as a parameter to function, which one is a right way:

Answers:

• doThis(&array)

• doThis(array)

• doThis(*array)

• doThis(array[size])

39. What will this code print out?   #include <stdio.h>  void function(char *name) { 	name=NULL;  }   main() {  	char *name="ELANCE"; 	function(name); 	printf("%s",name);   }

Answers:

• ELANCE

• Sengmentation Fault

• It Won't Compile

• NULL

40. What is the output of printf("%d\n", sizeof(long) / sizeof(int))?

Answers:

• Completely unknown, it depends on the implementation.

• 1

• Partially unknown, but always greater than 1.

• 2

• 4

41. stdarg.h defines?

Answers:

• array definitions

• arguments with data types

• formal arguments

• actual arguments

• macros used with variable argument functions

42. What does malloc(0) return?

Answers:

• The program segfault

• The behavior is implementation-defined

• NULL

• A unique pointer

43. Predict the output ::  main() {     float a = 1;     switch(a) {       case 1 :         printf("Hi");        case 1.0 :         printf("Hello");        default :         printf("Default");         break;     } }

Answers:

• Error, float can't be used in switch

• Default

• Hi

• HiHelloDefault

• Hello

44. struct mystruct {     int a;     float b; };  struct mystruct *ptr;  Which of these expressions will access member a?

Answers:

• *(ptr).a;

• *ptr->a;

• (*ptr).a;

• ptr.a;

45. Which one is not a bitwise operator ?

Answers:

• <<

• ~

• !

• |

• ^

46. What does the following do? int j = 10;     while (j --> 0){     printf("%d ", j);   }printf("\n");

Answers:

• 10 9 8 7 6 5 4 3 2 1

• Operator --> does not exist

• 9 8 7 6 5 4 3 2 1 0

• It segfaults

47. What will be the output of the following program:  #include<stdio.h>  int main(){     int a[] = { 1, 2, 4, 8, 16, 32 };      int *ptr, b;      ptr  = a + 64;      b = ptr - a;     printf("%d",b);     return 0; }

Answers:

• 8

• 16

• 64

• 32

• Segmentation violation

48. What is the output of the following code:  char str[10] = "abcd"; char * p1, *p2;   p1 = str; p2 = str;  *p2 = 'A';    printf ( "%s %s", p1, p2 );

Answers:

• Undefined

• abcd Abcd

• It won't compile

• Abcd Abcd

49. What will be the output?  main() {    float a=1.1;      double b=1.1;      if(a==b)      printf("True");      else      printf("False"); }

Answers:

• Normally False, but could be True depending on implementation.

• Error, it's not legal to compare a float with a double without a cast.

• Always True, regardless of implementation.

50. What is meaning of following declaration? int(*p[3])();

Answers:

• None of these

• p is pointer to function

• p is pointer to function that return array

• p is pointer to array of functions

• p is array of pointers to functions

51. What is the output of the following code?  char * str1 = "abcd"; char * str2 = "xyz";   printf ( "%d %d", strlen(str1) - strlen(str2), sizeof(str1) - sizeof(str2));

Answers:

• 1 0

• 1 undefined

• Compile time error

• 1 1

52. Which of the following data type is scalar?

Answers:

• Float

• Array

• Pointer

• Union

53. The main() function can be called recursively.

Answers:

• True

• False

54. Sort these integer constants from smallest to largest.

Answers:

• 40, 040, 0x40

• 0x40, 40, 040

• 0x40, 040, 40

• 040, 40, 0x40

55. #include <stdio.h> #define FUNC(A,B) #B#A int main() {   printf(FUNC(AA,BB)); } What does it print?

Answers:

• Nothing! It doesn't compile

• BBAA

• AA

• AABB

• BB

56. int a = 1, b; a = 1 & b = 2;  what's the result of a and b?

Answers:

• It doesn't compile.

• 1, 2

• 1, undefined

• 0, 2

• undefined, undefined

57. memmove() is safer than memcpy()

Answers:

• False

• True

58. What will be the output?  #include <stdio.h>  int main() {     char c = 125;     c = c + 10;     printf("%d", c);      return 0; }

Answers:

• It is implementation dependent.

• 135

• 7

• -121

• 8

59. What is the difference between fopen and open?

Answers:

• open is deprecated, fopen is not

• fopen opens a stream which is buffered.

• fopen open files. open can open files and directory.

• open is safer than fopen.

60. What are i and j after this code is executed??  #define Product(x) (x*x)  main() {     int i , j;     i = Product(2);     j = Product(1 + 1);     printf("%d %d\n", i , j); }

Answers:

• 4 4

• 4 1

• 2 2

• Error in Statement :: Product ( 1 + 1 )

• 4 3

61. For a 3 dimensions array[2][3][4] how many call to malloc do you need at least?

Answers:

• 1

• 2

• 3

• 4

• 24

62. Currently, what does GCC stand for?

Answers:

• GNU C Compiler

• Great C Compiler

• GNU Code Compiler

• GNU Compiler Collection

63. What is the difference between "void foo();" and "void foo(void);"?

Answers:

• void foo(); is not correct C.

• void foo() can take any arguments while void foo(void) can take none.

• There is no difference, they are equivalent.

• void foo(void); is not correct C.

• Neither void foo(); nor void foo(void); are correct C.

64. Is this code valid in C89? #define RED "\033[31m" #define END "\033[0m" puts("Hello " RED "world" END " !");

Answers:

• It's a GNU extension

• Yes

• No

65. What is the output of the following program: #include "stdio.h" int main( ) { printf( "%d %d", sizeof(" "),sizeof(NULL) ); return 0; }

Answers:

• NULL

• Compile time error

• None of these

• Nothing appear, program closed after execution.

66. Which one is a reserved keyword?

Answers:

• redirect

• rearrange

• real

• reserved

• restrict

67. #include <stdio.h> int main() {     int n;     n = 2, 4, 6;     printf("%d", n);     return 0; } what is the output?

Answers:

• 6

• undefined

• 2

• compiler error

• 4

68. What is the output of the Program :  main() {     int i,j;     i=1,2,3;     j=(1,2,3);     printf("%d %d",i,j); }

Answers:

• Compile Time Error

• Garbage Values of i & j

• 1 3

• 1 1

• 0 0

69. How many "-" will be printed out by running the following code:  #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main(void) {    int i;    for(i=0; i<2; i++){       fork();       printf("-");    }    return 0; }

Answers:

• 6

• 2

• 8

• 4

70. What does this code do? printf("%u", -08);

Answers:

• Prints whatever number UINT_MAX-7 is.

• Prints whatever number UINT_MAX-8 is.

• It doesn't even compile.

• Prints the number -8.

71. with  sizeof(char) == 1 sizeof(char *) == 4  char *a, *b; a = b; b++; What is (b - a)?

Answers:

• It segfaults

• 1

• 4

• It depends

72. How many "-" will be printed out by running the following code:  #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main(void) {    int i;    for(i=0; i<2; i++){       fork();       printf("-\n");    }    return 0; }

Answers:

• 6

• 4

• 8

• 2

73. #include<stdio.h>  int main(){ char *string="smarterer"; printf("%d",printf("%s",string)); return 0; } What is the output?

Answers:

• 9smarterer

• Compiler error

• garbage value

• smarterer9

• smarterer10

74. What is the output: register int n; printf("%u",&n);

Answers:

• runs with warning

• garbage value

• address of n

• run time error

• compile time error

75. What is the value of i after : int i; i = 10; i = i++ + i++;

Answers:

• 23

• 22

• 20

• It's implementation dependent

• 21

76. #include <stdio.h> #define SQR(x) (x*x) void main(void) {      int x, y;      x = 5;      y = SQR(++x);      printf("y is %d\n", y); }

Answers:

• y is 49

• y is 36

• y is 30

• y is 25

77. What is the output of the following program: #include <stdio.h> void main() {  int j,k=10,l=-20,a=8,b=4;   j = --k - ++l * b / a;  printf("Z= %d \n",j); }

Answers:

• Z=16

• Z=18

• Z=20

• Compile time error

78. Give the output ::  main() { int i=10 , j=0, a,b; a = i || j++ ; b = j && i++; printf("%d, %d, %d, %d",a,b,i,j); }

Answers:

• 0, 1, 10, 0

• 1, 1, 10, 0

• 1, 1, 11, 1

• 1, 0, 10, 0

• 1, 0, 11 ,1

79. Which of these is NOT correct syntax?

Answers:

• struct struct { int a; float b; };

• struct { int a; float b; };

• struct stru { int a[10]; int b=0; };

80. #include <stdio.h>  int main() {     int i=-1, j=-1;      (i = 0) && (j = 0);     (i++) && (++j);      printf("%d,%d\n", i, j);     return 0; }  What is the output of that program?

Answers:

• 1, -1

• 0, 1

• 0, 0

• 1, 0

• 1, 1

81. Which command-line flag will dump the output of the preprocessor from gcc?

Answers:

• --preprocessing

• -H

• -E

• -C

82. int a=2, b=3, c=4; int res; res=c>b>a;  What is the value of res?

Answers:

• -1

• We don't know

• 0

• Compilation error

• 1

83. After char *foo = calloc(1, 2); what is the value of *foo?

Answers:

• Unknown, it depends on what memory block it got assigned to.

• 1

• 2

• 0

84. Does "gcc -Wall" print all warnings?

Answers:

• Yes

• No

• It depends

85. What does "11 | 4 == 15" evaluate to?

Answers:

• 11

• 15

• 0

• 1

86. What will the following code print?  void *p = malloc(0); printf ("%d\n", *p);

Answers:

• Nothing, it will give a runtime error.

• Unknown, it depends on what pointer malloc returns.

• 0

• Nothing, it won't compile.

87. The system function longjmp() can be used to return execution control to any user-specified point in the active function call tree.

Answers:

• False

• True

88. The end of a C statement is indicated by this character.

Answers:

• +

• .

• ;

• :

89. What is the output of printf("%d\n", sizeof(long) / sizeof(int))?

Answers:

• Depends on the implementation, but always some number > 1.

• 4

• Depends on the implementation, but always some number >= 1.

• 1

• 2

90. What will be the output?  void main() {       int const *p = 9;       printf("%d", ++(*p)); }

Answers:

• Compiler Error

• 10

• 9

• Runtime error

91. What is the difference between "void foo();" and "void foo(void);" in C?

Answers:

• Neither void foo(); nor void foo(void); are correct C.

• void foo(void); is not correct C.

• void foo(); is not correct C.

• There is no difference, they are equivalent.

• void foo() allows for calls with any number of arguments while void foo(void) does not allow for calls with any arguments.

92. This code will:  void main() {                 char const *p = "abcdef";                 printf("%s",*(p+4)); }

Answers:

• print "ef"

• print "e"

• print "def"

• not compile

• cause an error when run

93. void main() { char  *a; a="1234"; printf("%d",sizeof(a)); }

Answers:

• 2 bytes

• 4 bytes

• 1 bytes

• garbage value

• size not defined

94. What will be the output of this code?  #include <stdio.h> int main(void) {        int i = 1;           printf("%d", i+++i);        return 0; }

Answers:

• 3

• 2

• Compiler error

• 4

95. Which statement do you use to stop loop processing without a condition?

Answers:

• continue;

• jump;

• break;

96. Which keyword is needed to compile a method in Csharp which uses pointers?

Answers:

• void

• static

• unsafe

97. What is the purpose of the ref keyword in C#?

Answers:

• It allows you to reference a variable value from anywhere inside of your program.

• It allows you to pass a parameter to a method by reference instead of by value.

• It allows you to change the reference address of the variable.

98. Which of the following describes a C# interface?

Answers:

• An interface allows you to define how a class will be named.

• An interface is the UI presented to the user in an application.

• An interface contains only methods and delegates.

• Interface is a keyword that allows classes to inherit from other classes.

• An interface contains only the signatures of methods, delegates or events.

99. Which of the following is an example of an auto implemented property?

Answers:

• public string Name { }

• public string Name { get{ return m_name;} set{ m_name=value;} }

• public string Name { get; set; }

100. Classes that can be used for reading / writing files like TextReader, StreamWriter, File can be found in which namespace?

Answers:

• System.Text

• System.Stream

• System.DataAnnotations

• System.IO

• System.Data

101. Which statement is a convenient way to iterate over items in an array?

Answers:

• foreach

• for

• switch

102. What type of memory management does Csharp employ?

Answers:

• managed

• manual allocation

103. Given the following C# statement:   int[] myInts = { 5, 10, 15 };  What is the value of myInts[1]?

Answers:

• 15

• 5

• 10

104. Which classes are provided in C# for writing an XML file?

Answers:

• XMLReader

• XMLWriter

• XMLCreation

105. The keyword used to include libraries/namespaces in C# is:

Answers:

• using

• use

• include

• import

106. The purpose of the curly braces, { and }, in C#:

Answers:

• None of these

• is to delineate the end of a statement to be executed.

• is to mark function code to be used globally.

• is to mark the beginning and end of a logical block of code.

107. Which C# debugging tools are available to you with Visual Studio?

Answers:

• Stepping through your code

• Breakpoints

• All of these

108. If your Csharp class is called Cats, which statement creates an object of type Cats?

Answers:

• cats myCat = new cats();

• Cats myCat = new cats();

• Cats myCat = new Cats();

109. Csharp provides a built in XML parser.  What line is needed to use this feature?

Answers:

• using System.Parser

• using System.Xml;

• using System;

• using System.Strings

110. Exceptions can be handled in Csharp with a...

Answers:

• none of these

• Throw Exception

• try catch finally block

• ON ERROR Resume NEXT statement

111. The manifest of a C# assembly contains...

Answers:

• supported locales.

• version information.

• all of these

112. The default value of a reference type is...

Answers:

• null

• none of these

• 0

• unknown

113. C# support what types of inheritance.

Answers:

• All options.

• Interface inheritance

• Implementation inheritance

114. Which of the following is not a built-in data type in C#?

Answers:

• int

• single

• bool

• string

115. In order to create a filestream object in C#, what do you need to include in your program?

Answers:

• using System.Strings

• #include <System.IO>

• using System.IO;

116. Exceptions can be handled in C# with a...

Answers:

• try catch finally block

• Throw Exception

• none of these

• ON ERROR Resume NEXT statement

117. Choose the types of members which you can have in your C# class?

Answers:

• fields

• methods

• constructors

• all of these

118. A sealed class in C# means:

Answers:

• that the class cannot be used for inheritance.

• derived classes can override some of the class methods.

• that you can create objects of that class type.

119. The Code Document Object Model can be used for...

Answers:

• developing automatic source code generators.

• allowing developers to create their own code generation utilities.

• all of these

120. The foreach loop in C# is constructed as:

Answers:

• foreach (int i in collection)

• foreach (collection as int i)

• for (int i : collection)

• foreach (int i : collection)

• there is no foreach loop in C#

121. CSharp cannot be run without installing...

Answers:

• the Java Virtual Machine.

• the Common Language Runtime.

• all .NET languages.

122. In C#, what would you use to output the contents of a variable to the screen?

Answers:

• Console.Write() method

• Console.Print() method

• System.Write() method

123. What is the result of the following expression?  int x = 100 / 0;

Answers:

• The system will throw a MathFormatException

• The system will throw a DivideByZeroException more info

• x = NaN;

• x = null;

• The system will throw a InvalidOperationException

124. Valid parameter types for Indexers in C# are...

Answers:

• enum

• integer

• all of these

• string

125. What is the purpose of the following statement:  ~myClass() ?

Answers:

• It is a constructor for myClass instances.

• It is the destructor for myClass instances.

• It is a property called myClass.

126. Which option below is an Operator?

Answers:

• Binary

• All Options

• Ternary

• Unary

127. Where would you find the definition for the Stack<T> class?

Answers:

• System.Collections.Generic namespace

• System.Collections.Specialized namespace

• System.Data namespace

128. What do the following two lines of code demonstrate:  string Substring (int startIndex) string Substring (int startIndex, int length) ?

Answers:

• method overloading

• operator overloading

• method reflection

129. An Indexer in C# allows you to index a

Answers:

• Both class and struct

• class

• struct

130. Which keyword would be used in a class declaration to stop the class from being inherited?

Answers:

• sealed

• static

• extern

• out

131. What is the keyword to create a condition in a switch statement that handles unspecified cases?

Answers:

• if(...)

• finally

• default

• standard

• else(...)

132. Which class provides the best basic thread creation and management mechanism for most tasks in Csharp?

Answers:

• System.IO.Compression

• System.Runtime.Serialization

• System.Threading.ThreadPool

133. A static class in C# can only contain...

Answers:

• both static and non-static members

• none of these

• static members

• both private and public members

134. Given the following statement:  public enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }.  What is the value of Monday?

Answers:

• "Monday"

• 1

• none of these

• 0

135. bool test = true; string result = test ? "abc" : "def"; What is the value of result after execution?

Answers:

• testabc

• abc

• It doesn't compile.

• abcdef

• def

136. What does if((number <= 10) && (number >= 0)) evaluate to if number is -6?

Answers:

• False

• True

137. The C# statement: using System; means...

Answers:

• import the collection of classes in the System namespace.

• all of these

• create a namespace called system from the classes defined in this file.

138. If you know that a method will need to be redefined in a derived class,

Answers:

• you should declare it as virtual in the base class.

• you should declare it as private in the base class.

• you should declare it as partial in the base class.

139. What is the full name of the base type of all the types in .NET?

Answers:

• System.object

• Object

• System

• System.Object

• object

140. Which of the following best describes this class definition? : public class Foo<T> {}

Answers:

• This class implements the T class

• None of these

• It is a class which contains one or more arrays

• It is a generic class

• This class extends the T class

141. What is the full name of the type that is represented by keyword int?

Answers:

• System.Math.Int32

• System.Int

• System.Int64

• System.Int32

• Int32

142. An interface contains signatures only for

Answers:

• all of these

• methods

• properties

• events

• indexers

143. What is a jagged array in C#?

Answers:

• A multi-dimensional array with dimensions of the same size.

• A multi-dimensional array with dimensions of various sizes.

• An array of singular dimension with an unknown size.

144. When the protected modifier is used on a class member,

Answers:

• no other class instances can access it.

• the member can be accessed by derived class instances.

• it becomes the default access for all members of the class.

145. Which classes are provided in C# for navigating through an XML file?

Answers:

• Both XMLDocument and XMLReader

• XMLReader

• None of these

• XMLDocument

146. Reflection is used to...

Answers:

• dynamically invoking methods on a user's machine.

• viewing metadata.

• discover types and methods of assemblies on a user's machine.

• all of these

147. Given: var foo = 7%2; what is the value of foo?

Answers:

• 7

• 3.5

• 3

• 0.035

• 1

148. If you are overloading methods in a class the methods must have...

Answers:

• the same number of parameters.

• the same parameter types.

• the same name.

• none of these

149. You can attach a handler to an event by using which operator?

Answers:

• +=

• ++

• =

• ->

• =>

150. Which attribute specifies a method to run after serialization occurs?

Answers:

• OnSerializing

• OnDeserialized

• OnDeserializing

• OnSerialized

151. In C# the System.String.Format method is used for ....

Answers:

• Automatically formatting decimals into a currency string representation. Ex: 1000 becomes $1 000

• Replacing the format item in a specified string with the string representation of a corresponding object.

• Prettifying code snippets.

• Making the specified string wordwrapped for text visualization.

• Coloring a input string with different colors to be used for text visualization.

152. Can you change the value of a variable while debugging a C# application?

Answers:

• No, code gets "locked-down" during runtime.

• Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

153. During the class definition, inheritance in C# is acomplished by putting which of the following:

Answers:

• keyword "extends"

• keyword "inherits"

• all of the answers are correct

• ":" sign

154. What is unique about an abstract class in C#?

Answers:

• You cannot inherit another class from it.

• You can only instantiate a reference to it.

• You cannot create an instance of it.

155. In C#, methods with variable number of arguments:

Answers:

• can be created using the "params" keyword in argument list

• don't exist

• can be created using the "..." signs in argument list

156. How do you catch an exception indicating that you are accessing data outside of the bounds of the array?

Answers:

• catch(ArrayIndexOutOfBounds ex)

• catch(IndexOutOfRangeException ex)

• catch(InsufficientExecutionStackException ex)

• catch(ArrayTypeMismatchException ex)

157. Which of the following is not a C# keyword?

Answers:

• as

• of

• is

• if

• in

158. Which of the following declares your Csharp class as an attribute?

Answers:

• public class myAttribute as System.Attribute

• public class myAttribute : System.Attribute

• public class myAttribute

159. The extern keyword is used to declare a method which is...

Answers:

• implemented externally.

• implemented within the current project.

• implemented within one of the C# System classes.

160. When the public modifier is used on a class,

Answers:

• the class can be accessed by external dll's.

• it becomes the default access for all classes in your program.

• no other classes can access it inside of your program.

161. A struct differs from a class in C#

Answers:

• in that a struct can contain implementation inheritance.

• in that a class can be stored as either a reference or a value.

• in that a struct stores the value not a reference to the value.

162. Csharp provides an XML documentation comment syntax by prefacing your comment lines with...

Answers:

• ///

• /*

• //

163. How do you implement your own version of ToString() method in your class?

Answers:

• private override string ToString() { }

• public override string ToString() { }

• public override ToString() { }

• public string ToString() { }

• public virtual string ToString() { }

164. C# provides an XML documentation comment syntax by prefacing your comment lines with...

Answers:

• <!--

• //

• ///

165. What does the following statement do?:   DateTime? startDate;

Answers:

• allows you to create a reference to a value instead of a stored value

• makes the variable a runtime only variable

• allows you to set the variable startDate equal to null

166. In the following array instantiation:  string[] names = new string[2]; , how many items can the array hold?

Answers:

• 3

• 2

• 1

• 0

167. While handling an exception, "finally" block:

Answers:

• all of the answers are correct

• is always executed regardless of how the "try" block exits

• is useful for cleaning up any resources allocated in the "try" block

• can be used without "catch" block

168. From which class do you need to derive to implement a custom attribute?

Answers:

• System.AttributeUsage

• System.AttributeInfo

• System.Reflection.Attribute

• System.Attribute

• System.Object

169. Can you use pointers to manipulate memory in C#?

Answers:

• Yes, but only by using the unsafe keyword.

• No, it is not a feature of C#.

• No, C# objects are managed by garbage collection.

170. What is: #if ?

Answers:

• Compiler option

• Preprocessor directive

• Invalid syntax

• Condition

171. Extension methods in C#...

Answers:

• all of the answers are correct

• provide a way to add methods to existing types without modifying them

• provide a way to add methods to existing types without new derived type

• are a special kind of static method

• are called as if they were instance methods

172. A difference between a struct and a class is that...

Answers:

• none of these

• a struct acts like a value type.

• structs support inheritance.

• a struct is stored on the heap.

173. C# code is compiled in...

Answers:

• x86, x64 specific native code (or both), depending on compilation options

• Neutral bytecode, executed by the .Net virtual machine.

• Common Intermediate Language, compiled in CPU-specific native code the first time it's executed.

174. In order for the following to compile:  using (CustomClass = new CustomClass()) {  }   CustomClass needs to implement which interface?

Answers:

• ICustomAdapter

• Disposable

• IUsing

• IDisposable

• IMemoryManagement

175. When dealing with currency calculations you should always use what data type?

Answers:

• Int

• Int32

• Decimal

• Float

• Double

176. Applications written in C# require the .NET framework...

Answers:

• and the Visual Studio compiler to be installed on the machine running the application.

• all of these

• to be installed on the machine running the application.

177. Consider the following code:  static void Set(ref object value) {     value = "a string"; }  static void Main(string[] args) {     object value = 2;     Set(ref value); }  After the call to "Set", what will the value in "value" be?

Answers:

• "a string"

• 2

• It won't compile.

178. If your C# class is a static class called OutputClass, which contains public static void printMsg();, how would you call printMsg?

Answers:

• OutputClass oc = new OutputClass(); oc.printMsg();

• Both of these

• OutputClass.printMsg();

179. In C#, if you would like to create a class across multiple files, you should precede the class definition with...

Answers:

• the internal keyword

• the partial keyword

• the public keyword

180. In a Windows Forms application, the static void Main must have a [STAThread] attribute. What does it mean?

Answers:

• The [STAThread] marks a thread to use the Single-Threaded COM Apartment.

• The [STAThread] makes it possible to use multiple threads in your application.

• The [STAThread] marks the application to use Windows Forms components

• The [STAThread] makes it impossible to use multiple threads in your application.

181. Anonymous functions can see the local variables of the sourrounding methods.

Answers:

• False.

• True.

182. What is the default visibility for members of classes and structs in C#?

Answers:

• private

• internal

• public

• protected

183. Given the method:  static int Foo(int myInt, params int[] myInts, int myOtherInt) {     if (myInt > 1) return myOtherInt;      foreach (dynamic @int in myInts)         myInt += @int;      return myInt + myOtherInt; }  What will "Foo(1, 2, 3, 4, 5)" return?

Answers:

• 15

• 5

• 10

• Compiler error - parameter arrays must be the last parameter specified.

• Compiler error - The "dynamic" keyword cannot be used to assign foreach iteration variables.

184. In CSharp, what is the default member accessibility for a class?

Answers:

• public

• protected

• private

185. Which keyword would be used in the class definition if we did not want to create an instance of that class?

Answers:

• static

• sealed

• void

• private

186. Converting a value type to reference type is called....

Answers:

• Compilation

• Street magic

• Unboxing

• Typecasting

• Boxing

187. What happens with the following lines? #region Debug [block of code HERE] #endregion

Answers:

• You can visually expand or collapse the block of code.

• The entire block of code is commented.

• The entire block of code is executed just in debug mode.

188. Which of the following statements about static constructors are true?

Answers:

• The programmer cannot specify at what point in their program a static constructor will be executed.

• All answers are correct

• A static constructor cannot be called directly.

• A static constructor does not take access modifiers or have parameters.

189. C# is an object oriented language which does not offer...

Answers:

• simple types.

• global variables.

• classes.

190. Which line is required in your Csharp application in order to use the StringBuilder class?

Answers:

• using System.Strings

• using System.Text;

• using System;

191. In the code below.  public class Utilities : System.Web.Services.WebService {     [System.Web.Services.WebMethod]      public string GetTime()     {         return System.DateTime.Now.ToShortTimeString();     } }   [System.Web.Services.WebMethod]  is an example of what?

Answers:

• WebMethod

• Functional Property

• Attribute

• Method Setting

192. What does the following statement do?   #error Type Mismatch

Answers:

• Generates an error which can be caught by a try/catch block.

• Generates an exception.

• Generates a compiler error.

193. What's the best practice for enumerating all the values of a Suit enum?

Answers:

• foreach (Suit suit in Enum.GetValues(typeof(Suit))) { }

• foreach (string suit in Enum.GetNames(typeof(Suit))) { }

• C# does not allow enum enumeration.

194. C# delegates are object-oriented, type-safe, they can be created in anonymous functions, they can reference static or instance methods, and they do not know or care about the class of the referenced method.

Answers:

• True.

• False, there is one incorrect statement mixed with the correct ones.

195. The built-in string class in C# provides an immutable object which means...

Answers:

• that the value of the string object can be changed multiple times.

• all of these

• that the value of the string object can be set only once.

196. In the following statement: string[] words = text.Split(delimiterChars); what is the function of delimiterChars?

Answers:

• Contains an array of characters which are to be used to delimit the string.

• Contains a string which is to be split into words.

• Contains an array of characters to be split into words.

197. A struct can inherit from another struct or class.

Answers:

• False

• True

198. What description BEST suites the code below.  var Dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);

Answers:

• Code wont compile

• We're creating a standard dictionary object

• We're creating a case insensitive string dictionary

199. int a = 5; for (int i = 0; i < 3; i++) {      a = a - i; }  What is the value of the variable a after the code runs?

Answers:

• 3

• 1

• -1

• 0

• 2

200. Proper way of defining an extension method for a string class in C# is:

Answers:

• public static int WordCount(String str) : String

• public static int WordCount(this String str)

• public static int String.WordCount(String str)

• public static int WordCount(String, String str)

• public static int WordCount(String str) : this String

201. How do you declare a generic method that takes one parameter which must be a value type?

Answers:

• public void Test<struct T>(T t) { ... }

• public void Test<T>(T t) where T : struct { ... }

• public void Test<T : struct>(T t) { ... }

• public void Test<T>(T t) T is struct { ... }

202. What does the params method keyword do?

Answers:

• Allows a variable number of parameters to be used when a method is called.

• all of these

• Allows method parameters to be declared of any type.

203. Consider the following C# code:  int x = 123; if (x)   {    Console.Write("The value of x is nonzero."); }  What happens when it is executed?

Answers:

• It is invalid in C#.

• Prints "The value of x is nonzero." to the screen.

204. Which is an example of a C# main method?

Answers:

• all of these

• static void Main()

• none of these

• static int main()

205. int[] myArray = new int[10];   What will be the value of myArray[1]?

Answers:

• 10

• A null reference exception woulde be thrown unless myArray[1] is first initialized to a value.

• null

• 0

206. Consider the following statement:  string str = "abcdefg";.  How would get the length of str?

Answers:

• int strlength = str.Length();

• int strlength = str.Length;

• int strlength = str.sizeOf()

207. Which C# statement is equivalent to this:  int myInt = new int(); ?

Answers:

• int myInt = NULL;

• int myInt = 0;

• int myInt;

208. What does the Obsolete attribute do when used in conjunction with a class?

Answers:

• All of these

• It generates an error/warning when the class is used.

• It substitutes the newly specified class for the obsolete class.

209. Will the following code compile?   public class CustomClass : IDisposable {    }

Answers:

• Yes

• No

210. What will be the output of the following C# code: int num = 1; Console.WriteLine(NUM.ToString());

Answers:

• Compile time error

• 1

• None of the above

• Undefined value

211. The primary expression for initializing an anonymous object in C# is in the form of:

Answers:

• new {...}

• new T(...){...}

• None of the choices, strongly typed languages cannot support anonymous objects

• new T(...)

212. Consider the following code snippet: public class A {...} public class B: A {...} public class C:B {...} then from the following options, which one will give a compile time error?

Answers:

• C c = new C();

• A a = new B();

• B b= new A();

• B b = new B();

• A a = new C();

213. Which of the following is NOT a value type?

Answers:

• System.Boolean

• System.String

• System.DateTime

• System.Int32

• System.Char

214. The following program is expected to run, and after 500 ms write "OK" and exit, but fails to do that. How would you fix this?  class Test {     int foo;      static void Main()     {         var test = new Test();          new Thread(delegate()         {             Thread.Sleep(500);             test.foo = 255;         }).Start();          while (test.foo != 255) ;         Console.WriteLine("OK");     } }

Answers:

• Make Thread Priority to low

• Make foo volatile

• Wait 499 ms

• Make foo bool

• Give thread a name

215. You need to create a custom Dictionary class, which is type safe. Which code segment should you use?

Answers:

• None of the listed answers

• public class MyDictionary : Dictionary<string, string>

• public class MyDictionary {...} { Dictionary<string, string> t = new Dictionary <string, string>; MyDictionary dictionary = (MyDictionary) t; }

• public class MyDictionary : IDictionary

216. What is the purpose of [Flags] attribute?

Answers:

• Allow values combination for enumeration (enums)

• Mark a class as obsolete.

• Add metadata on elements, for documentation.

• It does not exist in C#

217. What is the main difference between ref and out parameters when being passed to a method?

Answers:

• "ref" parameters don't have to be initialised before passing to a method, whereas "out" parameters do.

• They are both same in every sense of the word.

• Variables marked with "ref" keyword cannot be readonly whereas "out" variables can be.

• "out" parameters don't have to be initialised before passing to a method, whereas "ref" parameters do.

• Variables marked with "out" keyword cannot be readonly whereas "ref" variables can be.

218. A static member of a class is:

Answers:

• Something that can be accessed through an instance.

• Both of these

• Neither of these

• Shared by all instances of a class.

219. You are creating a class to compare a specially formatted string. You need to implement the IComparable<string> interface. Which code segment should you use?

Answers:

• public bool Equals(string other)

• public int Equals(object other)

• public bool CompareTo(object other)

• public int CompareTo(string other)

220. In C#, "implicit" keyword is used to:

Answers:

• "implicit" keyword doesn't exist in C#

• create user-defined type conversion operator that will not have to be called explicitly

• turn explicit casts into implicit ones

• all of the answers are correct

221. Which of the following is NOT reference type?

Answers:

• System.Exception

• System.Drawing.Point

• System.Type

• System.String

222. What are the access modifiers available in C#?

Answers:

• private, protected, public, internal

• private, protected, public, protected internal

• private and public

• private, protected, public, internal, protected internal

• private, protected, public

223. In C#, "explicit" keyword is used to:

Answers:

• all of the answers are correct

• "explicit" keyword doesn't exist in C#

• explicitly cast types

• create user-defined type conversion operator that must be invoked with a cast

224. Default DateTime.MinValue is  "1/1/0001 12:00:00 AM"

Answers:

• False

• True

225. What namespaces are necessary to create a localized application?

Answers:

• System.Resources, System.Localization.

• System.Globalization, System.Resources.

• System.Data, System.Resources.

226. Which are not function members in a C# class?

Answers:

• Indexers

• Fields

• Destructors

• Events

• Operators

227. Are bool and Boolean equivalent?

Answers:

• No, bool is a value type and Boolean is a reference type

• Yes

• No, Boolean doesn't exist in C#

228. When comparing strings, which of the following Enum Type is utilized to specify the comparison culture and whether or not it will ignore the case of the string?

Answers:

• StringFormat

• StringUnit

• StringComparison

• StringComparer

229. Interfaces in C# cannot contain:

Answers:

• indexers

• implementation of methods

• all of the answers are correct

• events

230. void Main() { 	int x = 1000000; 	double d = checked(x*x); 	Console.WriteLine("{0:N}",d); } The execution result will be:

Answers:

• 1000000000000

• 1E+12

• A System.OverflowException will be thrown

• This code will not compile

• 1000000000000.00

231. In C# "new" keyword is used to...

Answers:

• All of the answers are correct

• create objects and invoke constructors

• hide an inherited member from a base class member

• restrict types that might be used as arguments for a type parameter in a generic declaration

232. How many string objects are created in this piece of code:  string first = "tick"; string second = first + "tech"; second += "fly";

Answers:

• 4

• 3

• 2

• 1

• 5

233. Polymorphism.  LET: public class BaseClass {     public string DoWork() { return "A"; }  }  public class DerivedClass : BaseClass {     public new string DoWork() { return "B"; } }  IF:  DerivedClass B = new DerivedClass(); BaseClass A = (BaseClass)B; A.DoWork();   What's the expected output?

Answers:

• Code won't compile

• B

• A

234. What is wrong with this code:  public enum @enum : ushort {         Item1 = 4096,         Item2 = 8192,         Item3 = 16384,         Item4 = 32768,         Item5 = 65536, }

Answers:

• Keyword, identifier, or string expected after verbatim specifier: @

• Constant value '65536' cannot be converted to a 'ushort'

• Unexpected type declaration 'System.UInt16'

• Invalid token ',' in class, struct, or enum.

• Everything is wrong

235. What is wrong with this code?  public struct Person {      public string FirstName { get; set; }      public string LastName { get; set; }       public Person()      {      }               public Person(string firstName, string lastName)       {          this.FirstName = firstName;          this.LastName = lastName;      }           }       public struct Customer : Person  {      public List<Order> Orders = new List<Order>();  }

Answers:

• Structs cannot contain explicit parameterless constructors

• All the answers

• Structs cannot have instance field initializers

• 'this' object cannot be used before all of its fields are assigned to

• Structs cannot inherit from other classes or structs

236. Polymorphism.  LET: public class BaseClass {     public virtual string DoWork()      {         return "A";      }  }  public class DerivedClass : BaseClass {     public override string DoWork()      {         return "B";      } }  IF:  DerivedClass B = new DerivedClass(); BaseClass A = (BaseClass)B; A.DoWork();   What's the expected output?

Answers:

• The code won't compile

• B

• A

237. True or False: We can create a sealed abstract class in c#.

Answers:

• True

• False

238. True or false? Types or members that have the access modifier "protected internal" can be accessed in C# only from types that SIMULTANEOUSLY satisfy these two conditions: 1) They are derived from the containing class 2) They are in the current assembly

Answers:

• True

• False

239. Which answer is not a valid C# 4.0 variable definition?

Answers:

• var c = new int[1];

• int[][] d = new int[1, 2];

• int[] a;

• var b = new [] { 1 };

• int[,] e = new int [2, 3];

240. In C#, difference between "new" and "override" is:

Answers:

• "override" works in one-level inheritance, "new" is multilevel

• all of the answers are correct

• "new" is used to overload a method, "override" to override

• "new" explicitly hides a member inherited from a base class

241. The main reflection methods to query attributes are contained in the...

Answers:

• System.Reflection.MemberInfo class

• System.Reflection.GetCustomAttributes

• System.Collections.Attributes

242. C# provides Finalize methods as well as destructors, unlike Java. Which of the following is true about it?

Answers:

• That's not true, C# doesn't provide destructors.

• Destructor cannot be directly implemented, however it is implicitly called by Finalize method, which can.

• Finalize method cannot be directly implemented, however it is implicitly called by destructor, which can.

• Finalize method is the destructor in C#.

243. Which of the following will set the process return code to 1?

Answers:

• Environment.Result = 1

• Environment.ExitCode = 1

• void Main() { return 1; }

• Application.ExitCode = 1

• Console.ErrorLevel = 1,

244. In C#, what is the difference between: "int[,] arrayName;" and "int[][] arrayName;"

Answers:

• "int[,] arrayName;" is not correct declaration

• "int[,] arrayName;" is multidimensional array, while "int[][] arrayName;" is jagged array (array of arrays)

• There is no difference, they mean the same

• "int[][] arrayName;" is not correct declaration

• "int[][] arrayName;" is multidimensional array, while "int[,] arrayName;" is jagged array (array of arrays)

245. interface ICat{ void Meow(); } class Robot:ICat { void ICat.Meow() {} } void Main() { Robot robot = new Robot(); robot.Meow(); } This code is an example of:

Answers:

• Explicit interface member implementation, with invalid method call.

• Implicit interface member implementation, with invalid method call.

• Explicit interface member implementation, with valid method call.

• Implicit interface member implementation, with valid method call.

246. What does the @ symbol do when used in C# code?

Answers:

• Stops string literal escape sequences being processed.

• Allows you to use reserved keywords as variable names.

• Both stops string literal escape sequences being processed and allows you to use reserved keywords as variable names.

• None of these

247. What is the result of following function?  public bool SomeTest(){   return "i like c#".ToUpper().Equals("I LIKE C#");	 }

Answers:

• False, whatever the current culture

• Either true or false, depending on the current culture

• True, whatever the current culture

248. What is the expected output?  static void Main() { 	object o = -10.3f; 	int i = (int)o; 	Console.WriteLine(i); }

Answers:

• 10

• Runtime exception (InvalidCastException)

• Compile time error

• -10

• 0

249. enum Score { Awful, Soso, Cancode } Given the enum above, which statement(s) will generate a compiler error?

Answers:

• Score cancode = (Score)2;

• Score soso = 1;

• All of them(because enum Score: int type was not specified in declaration).

• Score awful = 0;

• None of them(all three will compile and execute just fine).

250. Given code:  var foo = 7; var bar = ++foo + foo++;  what is the value of bar?

Answers:

• 14

• 15

• 18

• 17

• 16

251. [Flags] enum Days{     None=0x0,     WeekDays=0x1,     WeekEnd=0x2 }  Days workingDays = Days.WeekDays | Days.WeekEnd;  How do you remove the Days.WeekEnd from the workingDays variable?

Answers:

• workingDays |= ~Days.WeekEnd;

• workingDays &= !Days.WeekEnd;

• workingDays &= ^Days.WeekEnd;

• workingDays &= ~Days.WeekEnd;

• workingDays |= !Days.WeekEnd;

252. Given the following code: var result = 7/2; what will be the value of result?

Answers:

• 3

• 3.5

• 3.49999999

• 4

• This code won't compile

253. abstract class BaseClass  {          public abstract Color Color          {               get { return Color.Red; }          } }  sealed class Blues: BaseClass  {          public override Color Color          {               get { return Color.Blue; }          } }  BaseClass test = new Blues();  What is the result of test.Color ?

Answers:

• Red

• Compilation error

• InvalidOperationException

• Blue

• null

254. What is the output of Console.WriteLine(10L / 3 == 10d / 3);?

Answers:

• False

• True

• Nothing, you will get a compiler error

255. namespace DocGen { class Skills<T> { public void Test(T t) { } } } According to C# standards and specifications, the documentation generator ID string corresponding to "Test" method from the code above should be:

Answers:

• "M:DocGen.Skills.Test(ret void, param System.Type):ContainsGenericParameters=true"

• "M:DocGen.Skills`1.Test(`0)"

• All of them

• "///<Method ret="void" param="T" ns="DocGen" class="Skills" public="true"> Test </Method>"

• "M:DocGen.Skills.Test(T)"

256. In the context of (A | B) and (A || B), the (A || B) boolean evaluation is known as what?

Answers:

• Time's Up!

• A "default" evaluation

• A "cross-circuit" evaluation

• A "standard" evaluation

• A "comparative" evaluation

• A "short-circuit" evaluation

257. Given the C# syntax for a method,  attributes modifiers return-type method-name(parameters ), what does the attribute [Conditional("DEBUG")] on a method indicate?

Answers:

• The method will always execute when called correctly.

• The method will only execute if you compile with the debug flag.

• The method can only execute if the program has defined DEBUG.

258. When can you assign a value to a readonly field?

Answers:

• In the field constructor.

• Neither of these

• Both of these

• In the declaration of the field.

259. What is the size of a long on a 32 bit operating system in C#?

Answers:

• Signed 64 bit integer

• Signed 32 bit integer

• Unsigned 32 bit integer

• Unsigned 64 bit integer

260. void Disagree(ref bool? maybe) { 	maybe = maybe ?? true ? false : maybe; } When calling this method, the value of the reference parameter will be changed to:

Answers:

• false if the previous value was true or false, true if it was null.

• true.

• false.

• The logical negation of the previous value, or true if it was null.

• null.

261. Does return 10 as long; compile?

Answers:

• No, because 10 cannot be cast to long

• No, because long is not a reference or nullable type

• No, because there is no as operator in C#

• Yes

262. Which of these is NOT a way to create an int array?

Answers:

• var e = Array.CreateInstance(typeof(int), 1);

• var a = new int[];

• var b = new int[0];

• var c = new [] { 0 };

• int[] d = null;

263. Can multiple catch blocks be executed?

Answers:

• Yes, catches excute in sequential order, then the control is transferred to the finally block (if there are any)

• No, once the proper catch code fires off, the control is transferred to the finally block (if there are any)

264. If A = true and B = false, how does  [1.]  (A | B)    differ from  [2.]  (A || B)

Answers:

• In [2.], B will be evaluated, in [1.] it wont

• In [1.], B will be evaluated, in [2.] it won't be.

• They're the same, just different ways of writing an OR statement.

• In [1.], A will be evaluated, in [2.] it wont

265. If you would like to create a read-only property in your C# class:

Answers:

• Do not implement a set method.

• Both of these

• Mark the set method as private.

• Neither of these

266. What does the following statement do:  delegate double Doubler(double x); ?

Answers:

• Creates a method which may be called by any class.

• Creates a type for the method Doubler.

• Creates a signature for the method Doubler in the delegate class.

267. Consider the following C# code:  int x = 123; if (x)   {    Console.Write("The value of x is nonzero."); }  What happens when it is executed?

Answers:

• It is invalid in C#.

• Prints "The value of x is nonzero." to the screen.

268. The [Flags] attribute indicates that an enum is to be used as a bit field. However, the compiler does not enforce this.

Answers:

• true

• false

269. In C#, a subroutine is called a ________.

Answers:

• Managed Code

• Method

• Metadata

• Function

270. Reflection is used to...

Answers:

• viewing metadata.

• all of these

• dynamically invoking methods on a user's machine.

• discover types and methods of assemblies on a user's machine.

271. When the public modifier is used on a class,

Answers:

• no other classes can access it inside of your program.

• the class can be accessed by external dll's.

• it becomes the default access for all classes in your program.

272. True or false: A class can implement multiple interfaces

Answers:

• False

• True

273. What are the access modifiers available in C#?

Answers:

• protected, internal, private

• public, protected, internal, private

• public, private

• public, internal, private

• public, protected, private

274. bool test = true; string result = test ? "abc" : "def"; What is the value of result after execution?

Answers:

• testabc

• def

• It doesn't compile.

• abc

• abcdef

275. Can you change the value of a variable while debugging a C# application?

Answers:

• No, code gets "locked-down" during runtime.

• Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

276. Given the following statement:  public enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }.  What is the value of Monday?

Answers:

• 1

• 0

• none of these

• "Monday"

277. In C#, methods with variable number of arguments:

Answers:

• don't exist

• can be created using the "params" keyword in argument list

• can be created using the "..." signs in argument list

278. During the class definition, inheritance in C# is acomplished by putting which of the following:

Answers:

• ":" sign

• keyword "inherits"

• keyword "extends"

• all of the answers are correct

279. The following line of code in C#: IEnumerable<int> aList = new List<int>();

Answers:

• Illegal because the constructor of List cannot be empty

• Illegal because List does not implement IEnumerable interface

• Illegal because it is not allowed to create an object of interface type

• Legal

280. C# code is compiled in...

Answers:

• Common Intermediate Language, compiled in CPU-specific native code the first time it's executed.

• Neutral bytecode, executed by the .Net virtual machine.

• x86, x64 specific native code (or both), depending on compilation options

281. What is the purpose of the [STAThread] attribute?

Answers:

• The [STAThread] marks a thread to use the Single-Threaded COM Apartment.

• The [STAThread] makes it impossible to use multiple threads in your application.

• The [STAThread] makes it possible to use multiple threads in your application.

• The [STAThread] marks the application to use Windows Forms components

282. What is the result of the following code?  var a = 3; a = "hello"; var b = a; Console.WriteLine(b);

Answers:

• It outputs "3"

• A compilation error

• It outputs "hello"

• A run-time error

283. Consider the following code:  static void Set(ref object value) {     value = "a string"; }  static void Main(string[] args) {     object value = 2;     Set(ref value); }  After the call to "Set", what will the value in "value" be?

Answers:

• "a string"

• 2

• It won't compile.

284. What description BEST suites the code below.  var Dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);

Answers:

• We're creating a standard dictionary object

• We're creating a case insensitive string dictionary

• Code wont compile

285. What is the main difference between ref and out parameters when being passed to a method?

Answers:

• Variables marked with "out" keyword cannot be readonly whereas "ref" variables can be.

• Variables marked with "ref" keyword cannot be readonly whereas "out" variables can be.

• They are both same in every sense of the word.

• "ref" parameters don't have to be initialised before passing to a method, whereas "out" parameters do.

• "out" parameters don't have to be initialised before passing to a method, whereas "ref" parameters do.

286. Are bool and Boolean equivalent?

Answers:

• No, Boolean doesn't exist in C#

• Yes

• No, bool is a value type and Boolean is a reference type

287. Given the method:  static int Foo(int myInt, params int[] myInts, int myOtherInt) {     if (myInt > 1) return myOtherInt;      foreach (dynamic @int in myInts)         myInt += @int;      return myInt + myOtherInt; }  What will "Foo(1, 2, 3, 4, 5)" return?

Answers:

• 10

• 5

• Compiler error - The "dynamic" keyword cannot be used to assign foreach iteration variables.

• 15

• Compiler error - parameter arrays must be the last parameter specified.

288. In C#, "explicit" keyword is used to:

Answers:

• explicitly cast types

• "explicit" keyword doesn't exist in C#

• create user-defined type conversion operator that must be invoked with a cast

• all of the answers are correct

289. What does the following code do?              string a = "hello";             string b = null;             string c = a + b;             Console.WriteLine(c);

Answers:

• It throws a NullReferenceException

• It outputs "a + b"

• It does not compile

• It outputs "c"

• It outputs "hello"

290. In C#, "implicit" keyword is used to:

Answers:

• "implicit" keyword doesn't exist in C#

• create user-defined type conversion operator that will not have to be called explicitly

• turn explicit casts into implicit ones

• all of the answers are correct

291. How many generations does the garbage collector in .NET employ?

Answers:

• 2

• 5

• 3

• 1

• 4

292. What is wrong with this code:  public enum @enum : ushort {         Item1 = 4096,         Item2 = 8192,         Item3 = 16384,         Item4 = 32768,         Item5 = 65536, }

Answers:

• Constant value '65536' cannot be converted to a 'ushort'

• Keyword, identifier, or string expected after verbatim specifier: @

• Unexpected type declaration 'System.UInt16'

• Everything is wrong

• Invalid token ',' in class, struct, or enum.

293. Polymorphism.  LET: public class BaseClass {     public string DoWork() { return "A"; }  }  public class DerivedClass : BaseClass {     public new string DoWork() { return "B"; } }  IF:  DerivedClass B = new DerivedClass(); BaseClass A = (BaseClass)B; A.DoWork();   What's the expected output?

Answers:

• A

• B

• Code won't compile

294. In C#, difference between "new" and "override" is:

Answers:

• "new" is used to overload a method, "override" to override

• "override" works in one-level inheritance, "new" is multilevel

• "new" explicitly hides a member inherited from a base class

• all of the answers are correct

295. What does the following code output?  bool isAlive = true; var d = new Dictionary<string,bool>(); d.TryGetValue("x", out isAlive); Console.WriteLine(isAlive ? "hello, " : "world");

Answers:

• hello, world

• hello,

• world

• isAlive

296. In C#, what is the difference between: "int[,] arrayName;" and "int[][] arrayName;"

Answers:

• "int[,] arrayName;" is multidimensional array, while "int[][] arrayName;" is jagged array (array of arrays)

• "int[][] arrayName;" is multidimensional array, while "int[,] arrayName;" is jagged array (array of arrays)

• "int[][] arrayName;" is not correct declaration

• "int[,] arrayName;" is not correct declaration

• There is no difference, they mean the same

297. Given the following code: var result = 7/2; what will be the value of result?

Answers:

• 3.49999999

• This code won't compile

• 4

• 3.5

• 3

298. In the context of (A | B) and (A || B), the (A || B) boolean evaluation is known as what?

Answers:

• A "standard" evaluation

• A "short-circuit" evaluation

• A "cross-circuit" evaluation

• A "default" evaluation

• A "comparative" evaluation

299. What is the value of Status.TiredAndHungry?  public enum Status {     Unknown = 0,     Sick = 1,     Tired = 2,     Hungry = 4,     TiredAndHungry = Tired | Hungry }

Answers:

• This does not compile

• 3

• 5

• 4

• 6

300. What is wrong with this code?  public struct Person {      public string FirstName { get; set; }      public string LastName { get; set; }       public Person()      {      }               public Person(string firstName, string lastName)       {          this.FirstName = firstName;          this.LastName = lastName;      }           }       public struct Customer : Person  {      public List<Order> Orders = new List<Order>();  }

Answers:

• 'this' object cannot be used before all of its fields are assigned to

• Structs cannot contain explicit parameterless constructors

• Structs cannot have instance field initializers

• All the answers

• Structs cannot inherit from other classes or structs

301. C# provides Finalize methods as well as destructors, unlike Java. Which of the following is true about it?

Answers:

• Finalize method is the destructor in C#.

• Finalize method cannot be directly implemented, however it is implicitly called by destructor, which can.

• Destructor cannot be directly implemented, however it is implicitly called by Finalize method, which can.

• That's not true, C# doesn't provide destructors.

302. Polymorphism.  LET: public class BaseClass {     public virtual string DoWork()      {         return "A";      }  }  public class DerivedClass : BaseClass {     public override string DoWork()      {         return "B";      } }  IF:  DerivedClass B = new DerivedClass(); BaseClass A = (BaseClass)B; A.DoWork();   What's the expected output?

Answers:

• The code won't compile

• A

• B

303. If A = true and B = false, how does  [1.]  (A | B)    differ from  [2.]  (A || B)

Answers:

• In [2.], B will be evaluated, in [1.] it wont

• In [1.], A will be evaluated, in [2.] it wont

• They're the same, just different ways of writing an OR statement.

• In [1.], B will be evaluated, in [2.] it won't be.

304. namespace DocGen { class Skills<T> { public void Test(T t) { } } } According to C# standards and specifications, the documentation generator ID string corresponding to "Test" method from the code above should be:

Answers:

• All of them

• "M:DocGen.Skills.Test(ret void, param System.Type):ContainsGenericParameters=true"

• "///<Method ret="void" param="T" ns="DocGen" class="Skills" public="true"> Test </Method>"

• "M:DocGen.Skills`1.Test(`0)"

• "M:DocGen.Skills.Test(T)"

305. Choose the valid C++ function declaration which passes the function parameters by reference.

Answers:

• ref myFunction(int a, int b, int c)

• void myFunction (int& a, int& b, int& c)

• void myFunction( int a, int b, int c)

306. Which is a requirement when using overloaded C++ functions?

Answers:

• Return types for the overloaded functions can be different.

• Argument lists for the overloaded functions must be different.

• One function can be static and the other can be nonstatic.

307. What is the difference between a class and a struct

Answers:

• The members of a class are private by default, and the members of a struct are public by default.

• You cannot overload an operator in a struct.

• They are the same.

• You can declare functions in a class, you cannot declare functions in a struct.

308. Which of the following statements assigns the hexadecimal value of 75 to a literal constant?

Answers:

• const int a = 4b;

• const int a = 0x4b;

• int a = 0x4b;

309. In the following variable definition, if declared inside a function body, what is the initial value of result:  int result; ?

Answers:

• 0

• NULL

• undefined

310. String literals can extend to more than a single line of code by putting which character at the end of each unfinished line?

Answers:

• a backslash (\)

• a tab (\t)

• a newline (\n)

311. What is the output of the following program?  #include <vector> #include <iostream>  int main () {   std::vector<int> int_values {3};    for (auto const& vv: int_values)    {     std::cout << vv;   } }

Answers:

• 333

• None of these

• Program fails during compilation

• 000

• 3

312. Suppose that a global variable "x" of type std::atomic<int> with an initializer parameter of 20 should be added to a header and (if necessary) source file so it is available to all files that include it.   How should this be implemented where it will cause neither compile nor linker errors when compiling multiple object files together?  Assume that a header guard and #include <atomic> is already present in the header (though not shown in the answers), and that C++11 is enabled.

Answers:

• In header: std::atomic<int> x = 20;

• In header: extern std::atomic<int> x; In source: extern std::atomic<int> x(20);

• In header: extern std::atomic<int> x(20);

• In header: extern std::atomic<int> x; In source: std::atomic<int> x = 20;

• In header: extern std::atomic<int> x; In source: std::atomic<int> x(20);

313. What will be the output?   	auto fn = [](unsigned char a){ cout << std::hex << (int)a << endl; }; 	fn(-1);

Answers:

• 0

• 256

• Undefined

• ff

• -1

314. What does OOD stand for?

Answers:

• Overly Objective Design

• Object-Oriented Design

• Object-oriented database

• Operating on Objects in Design

315. std::vector<int> foo {5}; (assume C++11)

Answers:

• Initializes a vector with 5 elements with value 0.

• Initializes a vector with 1 element of the value 5.

316. Classes can contain static member variables which are global to the class and...

Answers:

• none of these

• their values will change for each object of the same class.

• can be accessed by all objects of the same class.

317. What is the value of a = 11 % 3;?

Answers:

• 3

• 1

• 0

• 2

318. What is the value of i after the following statement(s)?  int i (4.36);

Answers:

• 4.4

• 5

• 4.36

• 4

319. int, long, double and string can all be described as:

Answers:

• Constructors

• Attributes

• Class members

• Data Types

320. Which of the following is not a loop structure?

Answers:

• do while loop

• stop when loop

• for loop

321. The C++ programming language derived from:

Answers:

• C

• French

• Fortran

• Basic

322. C++ statements are separated by this symbol:

Answers:

• Colon (:)

• Semi-colon (;)

• Hash symbol (#)

• Addition sign (+)

323. Which two variables are the same?

Answers:

• TEST and test

• test and test

• Test and test

324. The statement i += 5; has the same meaning as:

Answers:

• i == i;

• 5 += 1;

• i = i + 5;

• i * 5++;

325. Which of the following is not a fundamental data type in C++?

Answers:

• bool

• char

• wide

326. Which of the following operators below allow you to define the member functions of a class outside the class?

Answers:

• ,

• ?

• :%

• ::

327. What is taking place in this statement:    x == y;

Answers:

• x and y are sick of each other

• x and y are being checked for equality

• x is being assigned a value of y

• x will be divided by y

328. Which of the following is a valid C++ function declaration which does not return a value?

Answers:

• void myFunction( int a, int b)

• myFunction( int a, int b)

• int myFunction( int a, int b)

329. Which of the following is not a C++ primitive type?

Answers:

• int

• double

• float

• real

330. How do you declare an integer variable x in C++?

Answers:

• int x;

• x int;

• x is integer;

• declare x as integer;

• int<x>;

331. Which of the following is a reserved word in C++?

Answers:

• Char

• char

• CHAR

• character

332. Which of the following is a valid variable declaration statement?

Answers:

• int a, b, c;

• int a:

• int a; b; c;

333. The output of this program is  int main () { cout << "Hello World!"; return 0; }

Answers:

• Hello World

• Hello World!

• 0

• Syntax error

334. If you have two different C++ functions which have the same name but different parameter types, it is called...

Answers:

• recursive functions.

• inline functions.

• function overloading.

335. An ordered and indexed sequence of values is an:

Answers:

• Class

• List of Parameters

• Group

• Array

336. In C++, a single line comment needs to be begun with

Answers:

• a leading //.

• a leading /**.

• all of these

337. Choose the function declaration which you would use if you did not need to return any value.

Answers:

• myfunction(void)

• void myfunction()

• myfunction()

338. This symbol calls the pre-processor to include the specified system files such as iostream.

Answers:

• Exclamation Mark (!)

• Hash Symbol (#)

• Ampersand (&)

• Forward Slash (/)

339. The process of making one variable appear to be another type of data is called TYPECASTING.  The two processes are:

Answers:

• Forecasting and Fivecasting

• Expletive and Implicit

• Explicit and Implicit

• Single and double

340. Which is a valid comment statement in C++?

Answers:

• // this is a comment

• /* this is a comment */

• Both of these

341. A C++ program begins its execution at the

Answers:

• none of these

• main function.

• function specified by the preprocessor.

342. What does the following statement do: std::cout << x;?

Answers:

• Writes the character 'x' to stdout.

• Writes the contents of x to stdout.

• Stores the contents of x in the cout variable.

343. Which statement assigns to variable a the address of variable b?

Answers:

• a = b;

• a = *b;

• a = &b;

344. A global variable is a variable declared in the main body of the source code, outside all functions, while a local variable is one declared...

Answers:

• within the body of a function or block.

• all of these

• outside the main body of the function.

345. In the following line of C++ code, int foo[50]; what does the number 50 represent?

Answers:

• The initial value of the first array element.

• The maximum integer value that can be placed in the array.

• The number of integer elements the array shall hold.

346. What does operator+ perform on two instances of std::string?

Answers:

• none of these

• String concatenation

• Nothing

• Address addition

347. True or False: Classes can contain static member variables which are global to the class and can be accessed by all objects of the same class.

Answers:

• True

• False

348. What is the size in bytes of an int variable on a 32-bit system?

Answers:

• 2

• 3

• 1

• 4

349. How would you declare a pointer which has no type in C++?

Answers:

• int * data;

• null * data;

• void data;

• void * data;

350. What does the following statement mean?  const int a = 50;

Answers:

• none of these

• The value of a cannot change from 50.

• The initial value of a is 50 but you can change it.

351. The printmsg function does not require any arguments.  Choose the statement which calls the function.

Answers:

• printmsg;

• printmsg();

• void printmsg();

352. Choose the statement which declares a function with a default value for an argument.

Answers:

• void myfunction(int a)

• void myfunction(int a;a = 2)

• void myfunction(int a=2)

353. Which of the following statements tests to see if the sum is equal to 10 and the total is less than 20, and if so, prints the text string "incorrect."?

Answers:

• if( (sum == 10) || (total < 20) )printf("incorrect.");

• None of these options

• ctrl+alt+del

• if( (sum == 10) && (total < 20) )printf("incorrect.");

354. What is an advantage to using C++ Templates?

Answers:

• reduce code duplication

• templates are typesafe

• all of these

• increase code flexibility

355. Can constructors be overloaded?

Answers:

• Depends on the situation.

• No

• Yes

356. True or False: A void pointer is a special type of pointer which indicates the absence of a type for the pointer.

Answers:

• False

• True

357. std::make_heap() converts a range into a heap and std::sort_heap() turns a heap into a sorted sequence.

Answers:

• true

• false

358. Choose the statement which declares a function with arguments passed by reference.

Answers:

• void myfunction(int a, int b)

• void myfunction(int& a, int& b)

• void myfunction(int* a, int* b)

359. Consider the following:  namespace myNamespace { int a; int b; }  How would the main part of the program access myNamespace variable a?

Answers:

• myNamespace:a

• a

• myNamespace::a

360. What does the sizeof(arg) operator do?

Answers:

• returns the maximum value of arg

• returns the length in characters of arg

• returns the size in bytes of arg

361. What does the sizeof(arg) operator do?

Answers:

• returns the maximum value of arg

• returns the length in characters of arg

• returns the size in bytes of arg

362. Consider this code fragment:  a = 25;  b = &a;   What does b equal?

Answers:

• address of a

• value contained in the address of a

• 25

363. Consider this code fragment:  a = 25;  b = &a;   What does b equal?

Answers:

• address of a

• value contained in the address of a

• 25

364. Which of the following statements assigns the hexadecimal value of 75 to a literal constant?

Answers:

• Time's Up!

• const int a = 0x4b;

• int a = 0x4b;

• const int a = 4b;

365. What will "int a = 'a';" do?

Answers:

• It will declare a new variable a and set it to 97 (assuming a machine that uses ASCII).

• Nothing, it is an error and won't compile.

• It will declare a new variable a and set it to its previous value.

• It will cause an infinite loop.

366. True or False: In C++, a comment can only be specified with a leading //.

Answers:

• True

• False

367. Given the following code sample:  catch(???) { cout << "exception";}.  What do the ellipses indicate?

Answers:

• The handler will catch any type of error thrown.

• none of these

• The handler will only catch int exceptions.

• all of these

368. Why would you use the preprocessor directive #include <iostream> in your C++ program?

Answers:

• Your program uses cout function calls.

• Your program uses a return value.

• Your program uses standard elements.

369. The dynamic memory requested by C++ programs is allocated...

Answers:

• from high memory.

• from the memory heap.

• from extended memory.

• from the memory stack.

370. A structure item exists in your code with an integer member units.  You have the following variable declaration:  item * myItem;.  How do you access the value of units?

Answers:

• *(myItem.units)

• myItem->units

• myItem.units

371. What is the right way to place an opening curly bracket in C++?

Answers:

• There is no C++ rule about placing curly brackets.

• Opening curly brackets should always be placed on the same line with the statement referring to the block it defines.

• Curly brackets are not legal in C++ code.

• Opening curly brackets should always be placed on the next line after the statement referring to the block it defines.

372. Which is(are) an example(s) of  valid C++ function prototype(s)?

Answers:

• int myFunction(int, int);

• all of these

• int myFunction( int a, int b);

373. What does "int *p; p = 0;" do?

Answers:

• It zeroes out the memory that p is pointing to.

• It sets p to nullptr.

• It crashes your program.

• Nothing, it's illegal and won't compile.

374. If you have an external function which needs access to private and protected members of a class, you would specify the function as...

Answers:

• myClass myFunction(friend myClass);

• friend myClass myFunction(myClass);

• void myClass myFunction(myClass);

375. What does the following create:  int * p; p=0;?

Answers:

• Void pointer

• Both Null and Void

• Neither Null nor Void

• Null pointer

376. What's the difference between an array and a vector?

Answers:

• Vectors can hold data of different types, but arrays can only hold data of one type

• Arrays require the STL, but vectors are native to C++

• Vectors can be dynamically resized, but an array's size is fixed

• Vectors don't support random access to elements, but arrays do

• Arrays take more memory to store data than vectors

377. Which of the following is a valid variable identifier in C++?

Answers:

• class

• m_test

• 1_str

378. What does the line: #include <iostream> mean in a C++ program?

Answers:

• It tells the preprocessor to include the iostream standard file only if it it required by the program.

• It tells the program to include the standard library header files.

• It tells the preprocessor to include the iostream standard file.

379. char * array = "Hello"; char array[] = "Hello";  What is the difference between the above two, if any, when using sizeof operator ?

Answers:

• The sizeof of an array gives the number of elements in the array but sizeof of a pointer gives the actual size of a pointer variable.

• The sizeof returns the size of the char type (1) in both cases.

380. What is the value of  7 == 5+2 ? 4 : 3?

Answers:

• 7

• 4

• 3

381. What is the value of 2--2?

Answers:

• Nothing, that is not a valid C++ expression.

• 2

• 0

• 4

• -2

382. If your C++ program produces a memory leak, what could be a cause of the leak?

Answers:

• Dynamically allocated memory has not been freed.

• All of these

• The Garbage Collection routines have not run properly.

• None of these

383. If class B inherits class A, A::x() is declared virtual and B::x() overrides A::x(), which method x() will be called by the following code: B b; b.x();

Answers:

• A::x()

• A::x() followed by B::x()

• B::x()

• B::x() followed by A::x()

384. The default access level assigned to members of a class is...

Answers:

• protected

• public

• default

• private

385. Which of the following is not a specific type casting operator in the C++ language?

Answers:

• dynamic_cast

• unknown_cast

• reinterpret_cast

• const_cast

386. Defined data types (typedef) allow you to create...

Answers:

• alternate names for existing types in C++.

• different types in C++.

387. Which of the following can cause a memory corruption error?

Answers:

• All of these

• Freeing memory which has already been freed.

• Using an address before memory is allocated and set.

388. What is the difference between classes and structures?

Answers:

• None of these

• Elements of a class are private by default

• Classes can include members

• Structures cannot include types

389. Within a class declaration, the statement "virtual int foo() = 0;" does what?

Answers:

• Declares a default virtual function.

• Causes a compiler error.

• Declares a pure virtual function.

• Declares a volatile virtual function.

390. What does: #ifdef WIN32 tell the preprocessor to do?

Answers:

• If the variable WIN32 contains a value other than NULL, execute any statements following until a #endif statement is encountered.

• If the preprocessor directive WIN32 is defined, executed any statements following until a #endif statement is encountered.

• If the preprocessor directive WIN32 is defined, execute any statements following.

391. What does the following statement return:  int a(0);  cout << typeid(a).name();

Answers:

• int

• NULL

• 0

392. What does the following statement return:  int a(0);  cout << typeid(a).name();

Answers:

• int

• NULL

• 0

393. Can a struct have a constructor in C++?

Answers:

• No. Struct types do not support member functions.

• No. Only class types allow constructors.

• Yes.

394. In the following variable definition, what is the initial value of result:  int result; ?

Answers:

• 0

• undefined

• NULL

395. The following code sample demonstrates which form of type conversion?  short a(200); int b; b=a;

Answers:

• Implicit conversion

• Forced conversion

• Explicit conversion

396. Which of these is a difference between struct and class types?

Answers:

• Structs are public-inherited by default. Classes are private-inherited by default.

• No difference.

• There are no inheritances with structs. Classes may be derived.

• Structs only allow variable definitions. Classes also allow function definition.

397. std::vector<int> foo(5);

Answers:

• Initializes a vector with 5 elements of value 0.

• Initializes a vector with an element with the value 5.

398. A section of code designed to perform a specific job on data of predetermined type and size can be defined as:

Answers:

• Class

• Function

• Array

• Linked List

399. What are the two valid boolean (bool) values in C++?

Answers:

• TRUE and FALSE

• true and false

• True and False

400. Which is a valid variable initialization statement?

Answers:

• Both of these are valid

• int a = 0;

• int a(0);

401. What is the guaranteed complexity of std::push_heap?

Answers:

• O(log(n))

• O(n)

• O(1)

• O(n^2)

402. What is the size of the character array which would hold the value "Helloo"?

Answers:

• 6

• 8

• 7

403. A void pointer is a special type of pointer which indicates the...

Answers:

• absence of a type for the pointer.

• none of these

• pointer has a NULL value.

404. What is the data type for the following: L"Hello World"?

Answers:

• a string

• an integer string

• a wide character string

405. Where does the compiler first look for file.h in the following directive: #include "file.h" ?

Answers:

• The same directory that includes the file containing the directive.

• In the default directories where it is configured to look for the standard header files

• In all directories specified by the PATH environment variable on the machine.

406. In C++, what is the difference between these two declarations:  void foo(); void foo(void);

Answers:

• The second one is illegal.

• None, they are equivalent.

• The first one is illegal.

• One of them takes no value, the other takes any value.

407. True or False: A class that has a pure virtual method can be instantiated.

Answers:

• True

• False

408. What is the time complexity of delete the first variable in a deque object (e.g., deque<int> a;)?

Answers:

• O(n/2)

• O(logn)

• O(1)

• O(n)

409. Which class(es) can be used to perform both input and output on files in C++?

Answers:

• fstream

• All of the answers are correct.

• ifstream

• ofstream

410. class A { int x; protected: int y; public: int z; };  class B: public A {  };  What is the privacy level of B::y?

Answers:

• B does not inherit access to y from A.

• private

• public

• protected

411. Define a way other than using the keyword inline to make a function inline

Answers:

• The function must be defined inside the class.

• The function must be defined outside the class.

• The function must be defined as the friend function.

412. Per the C++11 standard, what does the following statement mean?   std::vector<int> vecInt{5};

Answers:

• 'vecInt' container has one element, whose value is 5

• None of these

• 'vecInt' container has five elements, each of which is initialized to a value of 0

• This statement is not a valid C++11 construct

413. class A { int x; protected: int y; public: int z; };  class B: private A {  };  What is the privacy level of B::z?

Answers:

• public

• B does not inherit access to z from A.

• private

• protected

414. int *array = new int[10]; delete array;

Answers:

• This code will correctly free memory

• This code has undefined behavior

415. Suppose int * a = new int[3];  How would you deallocate the memory block pointed by a?

Answers:

• delete[3] a;

• delete a[3];

• delete a[];

• delete[] a;

• delete a;

416. String literals can extend to more than a single line of code by putting which character at the end of each unfinished line?

Answers:

• a tab (\t)

• a backslash (\)

• a newline (\n)

417. In order to execute this statement, string mystring = "This is a string";, which statement is needed prior to this in your program?

Answers:

• using namespace std;

• Both of the other answers are correct.

• #include <string>

418. When should the class Foo have a virtual destructor?

Answers:

• Never

• When Foo also defines an assignment operator

• Always

• When Foo itself inherits from some other class

• When Foo is designed to be subclassed

419. Which of the following is a potential side-effect of inlining functions?

Answers:

• The size of the compiled binary increases

• The size of program's heap segment increases

• C++ standard guarantees that inlining does not result in any adverse side-effects

• The size of program's stack segment increases

420. What is a virtual function in C++?

Answers:

• A class member function that you expect to be redefined in derived classes.

• A class member function that must be redefined in derived classes.

• A class member function which does not need to be defined in the base class.

421. What of the following is not permitted in a pure virtual class in C++?

Answers:

• protected functions

• All of these are permitted.

• member variables

• static member variables

• private member variables

422. Which of the following rules apply to operator overloading in C++?

Answers:

• Cannot have default arguments

• Both of the other answers are correct.

• Cannot redefine the meaning of built in types

423. Which of the following calls method foo() from the parent class Parent of the current class?

Answers:

• Parent.foo();

• Parent::foo();

• this->parent->foo();

• Parent instance; instance.foo;

424. What is the value of x after the following code: int x = 0; if (x = 1) {   x = 2; } else {   x = 1; }

Answers:

• 1

• The code will not compile

• 0

• 2

425. What is the data range for an unsigned integer value in C++ on a system where ints are 32 bits?

Answers:

• 0 to 2,147,483,647

• 0 to 4,294,967,295

• ??0 to 255

• ??0 to 65,535

426. int a[] {1, 2, 3}; a[[] { return 2; }()] += 2;  What is the value of a[2]?

Answers:

• 3

• 4

• Undefined behavior

• Compile error: malformed attribute.

• 5

427. What does the "explicit" keyword do?

Answers:

• It prevents a single-argument constructor from being used in an implicit conversion

• It requires a variable to reside in main memory instead of a processor's cache

• It makes the declaration of a default constructor mandatory

428. What is the purpose of std::set_union?

Answers:

• Assigns one union to another union.

• Assigns a value to a union.

• Sets a value to the value of a union.

• Constructs a sorted union of the elements from two ranges.

• Constructs an unsorted union of the elements from two ranges.

429. Given the following, how many bytes of memory does var occupy?: class a {   int x;   short y; };  a var[20];

Answers:

• Depends

• 120

• This is invalid C++ code

• 4

• 160

430. Given: union a {   int x;   short y; };  a var[20];   How many bytes of memory does var occupy?

Answers:

• 4

• This is invalid C++ code

• 120

• 80

• Depends

431. What is the below code?  struct code { unsigned int x: 4; unsigned int y: 4; };

Answers:

• Invalid C++ code.

• A struct declaration with 2 arrays of int.

• A bit selector declaration.

• A bit field structure declaration.

• A struct with in place initialization of its members.

432. Is the following legal C++ code? | char *str = "abc" + "def";

Answers:

• Yes, but only if you #include <string> first.

• Yes.

• No.

• No, you need to add "const" before "char".

433. In the code below:  void foo(){   static int x=10; }  When is x created?

Answers:

• Every time foo() is called.

• At the first call of foo().

• When the process is created.

• The code will not compile.

434. Which of the following is not a member of std::weak_ptr<T>?

Answers:

• template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;

• template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;

• weak_ptr(T *r) noexcept;

• constexpr weak_ptr() noexcept;

435. class A { int x; protected: int y; public: int z; };  class B: public virtual A {  };  What is the privacy level of B::x?

Answers:

• protected

• private

• B does not inherit access to x from A.

• public

436. If you do not supply any constructors for your class, which constructor(s) will be created by the compiler?

Answers:

• Both of these

• Copy Constructor

• Default constructor

437. Will the code below compile without error? struct c0 {     int i;     c0(int x) {         i = x;     } }; int main() {     c0 x1(1);     c0 x2(x1);     return 0; }

Answers:

• No. c0 x2 ( x1 ) will return error.

• Yes.

• No. struct types do not have constructors.

• No. The constructor is not public.

438. What is the proper way to use the .substr() function on the following string to get the word "World"?  string aString = "Hello World!";

Answers:

• aString.substr(6,10);

• aString.substr(5,5);

• aString.substr(5,10);

• aString.substr(6,5);

439. Which is NOT a valid hash table provided by the STL?

Answers:

• hash_multimap

• hash_map

• hash_table

• hash_set

• hash_multiset

440. class A { int x; protected: int y; public: int z; };  class B: private A {   public:   using A::y; };  What is the privacy level of B::y?

Answers:

• B does not inherit access to y.

• public

• private

• protected

441. What will be the output?  	auto fn = [](unsigned char a){ cout << std::hex << (int)a << endl; }; 	fn(-1);

Answers:

• ff

• -1

• Undefined

• 0

• 256

442. An anonymous namespace is used to...

Answers:

• disambiguate declarations from other namespaces

• support closures

• nest namespaces

• prevent external access to declarations local to a compilation unit

443. Which function always returns an rvalue reference from "x", which can be used to indicate the object is going to be destroyed soon?

Answers:

• std::xvalue(x)

• std::shift(x)

• std::move(x)

• std::destroy(x)

444. According to the C++ standard, what is sizeof(void)?

Answers:

• 4

• 0

• 1

• It depends on the host computer's word size.

• Nothing, void doesn't have a size.

445. Where T is a type: std::vector<T>::at vs std::vector<T>::operator[]:

Answers:

• at is always bounds checked. operator[] is not.

• at is equivalent to operator[]

• at is not always bounds checked. operator[] is.

446. What is the output of the following program?  #include <vector> #include <iostream>  int main () {   std::vector<int> intValues {3};    for (const auto& vv: intValues)    {     std::cout << vv;   } }

Answers:

• None of these

• 000

• Program fails during compilation

• 3

• 333

447. std::deque<int> queue; queue.push_back(1); int& ref = queue.back(); queue.push_back(2);  Where does ref point to?

Answers:

• itr was invalidated by push_back

• Front of the queue

• Back of the queue

448. How do you declare a pointer where the memory location being pointed to cannot be altered, but the value being pointed to can?

Answers:

• int const *x = &y;

• const int * const x = &y;

• int * const x = &y;

• const int *x = &y;

• const int const *x = &y;

449. What type of exceptions can the following function throw:  int myfunction (int a);?

Answers:

• All

• None

• Standard

450. What will be the output of the following C++ code ?  #include<iostream>  class A {   int a;  public:   void foo() {std::cout<<"foo";}  };  int main() {   A* trial=nullptr;   trial->foo(); }

Answers:

• foo

• It's an incorrect program and causes segmentation fault.

• It's an incorrect program and can't be compiled either.

451. signed int a = 5; unsigned char b = -5; unsigned int c = a > b;  What is the value of c?

Answers:

• 1

• 0

• 255

• true

452. The value of "(sizeof(short) == sizeof(int) && sizeof(int) == sizeof(long))" is

Answers:

• true

• false

• implementation defined

• compiler error

453. Is the following well-formatted C++ code?  %:include <vector>  int main (void) <%     std::vector<int> ivec <% 1, 2, 3 }; ??>

Answers:

• Yes, it will compile.

• No, this is not valid C++ syntax.

454. With:  struct foo { int a:3, b:4, :0; int c:4, d:5; int e:3; };  Determine if each statement is true or false:  Concurrent modification of foo::a and foo::c is or might be a data race. Concurrent modification of foo::a and foo::b is or might be a data race. Concurrent modification of foo::c and foo::e is or might be a data race.

Answers:

• false false false

• false false false

• true true true

• false true false

• true false true

• false true true

455. What is the type being defined here:  typedef A (B::*C)(D, E) const;

Answers:

• B is defined to be a class containing a constant member function called A, taking arguments of types D and E, returning a pointer to type C.

• C is defined to be a constant member function pointer of class B taking arguments of types D and E, returning type A.

• A is defined to be a constant function in namespace B taking arguments of types D and E, returning a pointer to type C.

456. const std::string * s; std::string const * g;  What can be said about s and g?

Answers:

• s is an immutable pointer to a modifiable string g is a modifiable pointer to an immutable string

• s is a modifiable pointer to an immutable string g is an immutable pointer to an immutable string

• both s and g are modifiable pointers to an immutable string

• s is a modifiable pointer to an immutable string g is an immutable pointer to a modifiable string

457. According to the IEEE standard, which of the following will always evaluate to true if the value of "var" is NaN?

Answers:

• var > MAX_DOUBLE

• var < 0

• var == nan

• var != var

• var == "NaN"

458. int C++;  What is the value of C now?

Answers:

• C is still a good programming language but C++ is better

• This is invalid code in C++

• undefined

• Whatever C was before plus one

• 1

459. Which operator cannot be overloaded by a class member function?

Answers:

• *

• ++

• ==

• []

• ?

460. If sizeof(int)==4 what is sizeof(long)?

Answers:

• 8

• You cannot know because it depends on the machine

• 4

• At most 4

• At least 4

461. In the following class definition:  class my_lock {   std::atomic<int> data; public:   my_lock() : data{1} {}   void unlock() { data = 1; }   void lock(); }  which could be used to complete the lock function, assuming the purpose of the above code is to create a mutex-like locking mechanism? Assume C++11.

Answers:

• void my_lock::lock() { int exp(1); while (!data.compare_exchange_strong(exp, 0)) exp = 1; }

• void my_lock::lock() { int exp(0); while (!data.compare_and_swap(exp, 1)) exp = 0; }

• void my_lock::lock() { exp = 0; }

• void my_lock::lock() { int exp(1); while (!data.compare_and_swap(exp, 0)) exp = 1; }

• void my_lock::lock() { int exp(0); while (!data.compare_exchange_strong(exp, 1)) exp = 0; }

462. According to the C++11 standard, which of these is a keyword?

Answers:

• size_t

• uint32_t

• mint32_t

• char32_t

• final

463. What would the following program print?  class Printer{ public:     Printer(std::string name) {std::cout << name;} }; class Container{ public:     Container() : b("b"), a("a") {}     Printer a;     Printer b; }; int main(){     Container c;     return 0; }

Answers:

• Always "ba"

• Always "ab"

• Either "ab" or "ba". Implementation dependent.

464. Which of the following operators can you not overload?

Answers:

• , (comma)

• ()

• []

• ->

• . (dot)

465. If we have a class myClass , what can we say about the code:  myClass::~myClass(){    delete this;    this = NULL; }

Answers:

• It is incorrect, it does not release any of the member variables.

• It is correct, we avoid memory leaks.

• It won't compile

• It will cause a stack overflow

466. What is the value of bar(1) in:  int foo(int &x) { return ++x; }  int bar(int x) { x += foo(x); return x; }

Answers:

• None, that is not valid C++ code.

• 4

• 3

• 2

• 1

467. What is the difference between:   int a(0); and   int a = 0; ?

Answers:

• None

• int a(0); is not legal code in C++ because int is not a class

• int a(0) happens at compile time and int a=0 happens at runtime

• int a(0) works in C but int a = 0 works both in C and C++

• int a(0) calls the int ctor and int a=0 calls the operator= of the int class

468. Is it possible to create class instance placed at a particular location in memory?

Answers:

• No. Only allocation on stack or in dynamic memory is allowed.

• Only by dirty hack with reinterpret_cast.

• Yes, placement new does this.

469. Below code fails to compile.   class A { public:   int GetValue() const {       vv = 1;      return vv;   } private:   int vv; };  Which of the following choices results in fixing this compilation error?

Answers:

• Change the declaration of member 'vv' to 'mutable int vv'

• Change the declaration of member function 'GetValue' so it is 'non const'

• Any one of the specified choices fixes compilation error

470. What is the value of "v"? auto &p = 10; double v = p;

Answers:

• 10

• undefined

• 10.0lf

• compilation error

471. If after:   a* var = new a(); var's value is 0x000C45710  What is its value after:   delete var;

Answers:

• 0xcccccccc

• Undefined

• 0x000C45710

• 0x00000000

• 0xdeadbeef

472. What does "int *p = malloc(2);" do?

Answers:

• It will make p point to the number 2.

• It will crash your program (an int is four bytes long, not two).

• It will make p point to an uninitialized two-byte piece of memory allocated from the heap.

• Nothing, it will yield a type mismatch compiler error.

473. What will this program print? #include <iostream> void f(int){std::cout << "f ";} int g(){std::cout << "g "; return 0;} int h(){std::cout << "h "; return 1;} int main(){     f((g(), h()));     return 0; }

Answers:

• Compilation error: f() takes only one argument

• Always "g h f "

• Always "h g f "

• Implementation dependent: "g h f " or "h g f "

474. What will a declaration such as ???extern "C" char foo(int);??? do?

Answers:

• It ensures that foo's mangled link name matches that of the C compiler so it can be called from C functions.

• It tells the compiler that it should use C's calling convention for storing parameters and return values on the stack.

• It says that foo is an external function that will be compiled by the C compiler.

• It tells the linker that it should find foo in the external section named "C" in the compiled file.

• Nothing, it is a syntax error.

475. int* a = {1, 2, 3}; | Where are the 1,2,3 values stored?

Answers:

• This code is not valid C++

• On the stack

• On the heap

476. What does operator -> () do?

Answers:

• Defines the structure dereference operator for a class

• This operator does not exist in C++

• Creates a virtual this pointer that can be used outside the scope of the class

• Lets you define the pointer returned by this for a class

• Defines the structure reference operator for a class

477. What can we say about:  myClass::foo(){   delete this; } .. void func(){   myClass *a = new myClass();    a->foo(); }

Answers:

• None of these.

• It won't compile

• It will raise a stack overflow

• It will raise a segmentation fault

478. Can a static member function be declared as const?

Answers:

• Depends

• No

• Yes

479. double a = 1.0; double *p = &a; a = a/*p;  Which of the following statements about the code is true?

Answers:

• Variable a is divided by the value of itself.

• None of the above.

• Variable a is divided by the address of itself.

• /* means the start of comments.

480. Virtual inheritance is needed...

Answers:

• to not get multiple ambiguous copies of members of ancestor classes

• to enable polymorphism

• to enable runtime type information (RTTI)

• to inherit from classes in different modules

481. What type of exceptions will the following function throw:  int myfunction (int a) throw();?

Answers:

• Int

• None

• All

482. What is the value of (false - ~0)?

Answers:

• 0

• Unknown. That's implementation dependent.

• -1

• 1

• Nothing. It's a type mismatch error.

483. What is the effect of "const" following a member function's parameter declarations?

Answers:

• The function may be called on a const qualified object, and treats the object as const qualified.

• The function returns the same value for each set of arguments.

• The function can only be called on a const qualified instance of the class.

• The function cannot change the values of its parameters.

484. int a = 001 + 010 + 100;  What is the value of a?

Answers:

• 111

• 105

• 109

• 107

• 113

485. class foo { foo(){}; };  class boo : public foo { boo() : foo() {}; };  which standard allows compilation of this code.

Answers:

• none, the code wont compile

• c++98

• c++0x

• c++11

• c++03

486. In C++ the three STL (Standard Template Library) container adapters are:

Answers:

• stack, linked_list, queue

• vector, queue, list

• stack, linked_list, priority_queue

• stack, queue, priority_queue

487. Identifying classes by their standard typedefs, which of the following is NOT declared by the standard C++ library?

Answers:

• ostream & ostream::operator << ( streambuf * )

• istream & istream::operator >> ( void * & )

• ostream & ostream::operator << ( void * )

• istream & istream::operator >> ( streambuf & )

• ostream & ends( ostream & )


1 NOT Answered Yet Test Questions:

(hold on, will be updated soon)
488. What is the value of 10.10 % 3?

Answers:

• 1

• None, that is an invalid mix of types.

• 3.03

• 1.01

• 1.0