C 2015

1. 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

Answers:
• public string Name { }
• public string Name { get{ return m_name;} set{ m_name=value;} }
• public string Name { get; set; }
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
Answers:
• aString.substr(6,10);
• aString.substr(5,5);
• aString.substr(5,10);
• aString.substr(6,5);
Answers:
• 8
• You cannot know because it depends on the machine
• 4
• At most 4
• At least 4
Answers:
• None of these.
• It won't compile
• It will raise a stack overflow
• It will raise a segmentation fault
Answers: 2. Which of the following is an example of an auto implemented property?
3. If A = true and B = false, how does  [1.]  (A | B)    differ from  [2.]  (A || B)
string aString = "Hello World!";
4. What is the proper way to use the .substr() function on the following string to get the word "World"? 
5. If sizeof(int)==4 what is sizeof(long)?
6. What can we say about:  myClass::foo(){   delete this; } .. void func(){   myClass *a = new myClass();    a->foo(); }
7. What is the value of p in int a,b,*p; p=&a; b=**p; printf("%d",p);
8. The main() function can be called recursively.

• address of variable a
• value of variable b
• address of variable b
• value of variable a
Answers:
• True
• False
9. #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
10. 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
11. 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.
12. Which attribute specifies a method to run after serialization occurs?
Answers:
• OnSerializing
• OnDeserialized
• OnDeserializing
• OnSerialized
13. 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
14. What is the default visibility for members of classes and structs in C#?
Answers:
• private
• internal
• public
• protected
15. 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.
16. 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.
17. 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
18. 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
19. 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
20. 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.
21. 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
22. 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
23. 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
24. If after:   a* var = new a(); var's value is 0x000C45710  What is its value after:   delete var;
Answers:
• 0xcccccccc
• Undefined
• 0x000C45710
• 0x00000000
• 0xdeadbeef
25. 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
26. What is i after the following block of code is executed : int i; i = 10/5/2/1;
Answers:
• 5
• 0
• 1
• 4
27. Which of the following special symbols are allowed in a variable name?
Answers:
• _ (underscore)
• * (asterisk)
• - (hyphen)
• | (pipeline)
28. A C variable can start with a digit as well a letter.
Answers:
• False
• True
29. 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
30. 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])
31. 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;
32. 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
33. Sort these integer constants from smallest to largest.
Answers:
• 40, 040, 0x40
• 0x40, 40, 040
• 0x40, 040, 40
• 040, 40, 0x40
34. 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
35. 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
36. Currently, what does GCC stand for?
Answers:
• GNU C Compiler
• Great C Compiler
• GNU Code Compiler
• GNU Compiler Collection
37. 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
38. Which one is a reserved keyword?
Answers:
• redirect
• rearrange
• real
• reserved
• restrict
39. 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
40. #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
41. What type of memory management does Csharp employ?
Answers:
• managed
• manual allocation
42. Exceptions can be handled in Csharp with a...
Answers:
• none of these
• Throw Exception
• try catch finally block
• ON ERROR Resume NEXT statement
43. Exceptions can be handled in C# with a...
Answers:
• try catch finally block
• Throw Exception
• none of these
• ON ERROR Resume NEXT statement
44. 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
45. 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.
46. 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
47. What does if((number <= 10) && (number >= 0)) evaluate to if number is -6?
Answers:
• False
• True
48. Given: var foo = 7%2; what is the value of foo?
Answers:
• 7
• 3.5
• 3
• 0.035
• 1
49. 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.
50. C# provides an XML documentation comment syntax by prefacing your comment lines with...
Answers:
• <!--
• //
• ///
51. 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.
52. 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.
53. 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.
54. 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 { ... }
55. Will the following code compile?   public class CustomClass : IDisposable {    }
Answers:
• Yes
• No
56. 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
57. 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.
58. 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)
59. 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
60. 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];
61. 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
62. 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
63. 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
64. 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.
65. 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.
66. What will be the output?     auto fn = [](unsigned char a){ cout << std::hex << (int)a << endl; };         fn(-1);
Answers:
• 0
• 256
• Undefined
• ff
• -1
67. Which two variables are the same?
Answers:
• TEST and test
• test and test
• Test and test
68. 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
69. 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;
70. 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.
71. The default access level assigned to members of a class is...
Answers:
• protected
• public
• default
• private
72. Which of the following is not a specific type casting operator in the C++ language?
Answers:
• dynamic_cast
• unknown_cast
• reinterpret_cast
• const_cast
73. Defined data types (typedef) allow you to create...
Answers:
• alternate names for existing types in C++.
• different types in C++.
74. The following code sample demonstrates which form of type conversion?  short a(200); int b; b=a;
Answers:
• Implicit conversion
• Forced conversion
• Explicit conversion
75. What is the guaranteed complexity of std::push_heap?
Answers:
• O(log(n))
• O(n)
• O(1)
• O(n^2)
76. 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;
77. 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)
78. 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>
79. 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
80. 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.
81. 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
82. 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
83. 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;
84. 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
85. 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
86. 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
87. 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
88. 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
89. 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.
90. 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.
91. 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;
92. 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
93. 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
94. 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.
95. Which is NOT a valid hash table provided by the STL?
Answers:
• hash_multimap
• hash_map
• hash_table
• hash_set
• hash_multiset
96. 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
97. What will be the output?     auto fn = [](unsigned char a){ cout << std::hex << (int)a << endl; };         fn(-1);
Answers:
• ff
• -1
• Undefined
• 0
• 256
98. 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)
99. 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.
100. 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.


101. What type of exceptions can the following function throw:  int myfunction (int a);?
Answers:
• All
• None
• Standard
102. 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.
103. signed int a = 5; unsigned char b = -5; unsigned int c = a > b;  What is the value of c?
Answers:
• 1
• 0
• 255
• true
104. The value of "(sizeof(short) == sizeof(int) && sizeof(int) == sizeof(long))" is
Answers:
• true
• false
• implementation defined
• compiler error
105. 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.
106. 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
107. 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.
108. 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
109. Which operator cannot be overloaded by a class member function?
Answers:
• *
• ++
• ==
• []
• ?
110. 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; }
111. According to the C++11 standard, which of these is a keyword?
Answers:
• size_t
• uint32_t
• mint32_t
• char32_t
• final
112. 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.
113. Which of the following operators can you not overload?
Answers:
• , (comma)
• ()
• []
• ->
• . (dot)
114. 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
115. 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
116. 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
117. 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.
118. 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
119. What is the value of "v"? auto &p = 10; double v = p;
Answers:
• 10
• undefined
• 10.0lf
• compilation error
120. 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.
121. 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 "
122. 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.
123. 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
124. 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
125. Can a static member function be declared as const?
Answers:
• Depends
• No
• Yes
126. 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.
127. 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
128. What type of exceptions will the following function throw:  int myfunction (int a) throw();?
Answers:
• Int
• None
• All
129. What is the value of (false - ~0)?
Answers:
• 0
• Unknown. That's implementation dependent.
• -1
• 1
• Nothing. It's a type mismatch error.
130. 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.
131. int a = 001 + 010 + 100;  What is the value of a?
Answers:
• 111
• 105
• 109
• 107
• 113
132. 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
133. 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
134. 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".
135. 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
136. 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;
137. 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"
138. 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 & )
139. Which of the following is not a predefined variable type?
Answers:
• float
• int
• real
140. In C, a block is defined by...
Answers:
• angle brackets
• tabulations
• tags
• curly braces
• indentation
141. Is C Object Oriented?
Answers:
• Yes
• No
142. int *a, b;  What is b ?
Answers:
• An int
• It does not compile
• An int *
143. which of these is not valid keyword?
Answers:
• var
• double
• int
• char
• float
144. Which of the following is the correct operator to compare two integer variables?
Answers:
• equal
• ==
• =
• :=
145. What is the only function all C programs must contain?
Answers:
• main()
• start()
• program()
146. int i = 17 / 3; what is the value of i ?
Answers:
• 5
• 5.60
• 6
• 5.666666
• 6.0
147. In C language, && is a
Answers:
• Relational Operator
• None of them
• Logical operator
• Arithmetic Operator
148. What is the value of the variable x?  int x; x = 32 / 64;
Answers:
• Undefined
• 0.5
• 0
149. 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.
150. 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
151. int tab[3] = {0,1,2}; int i = 0; tab[++i] == ?
Answers:
• 1
• 2
• 0
152. How can you make an infinite loop in C?
Answers:
• All answers are right.
• while(1) { }
• for(;;) { }
• loop: ... goto loop;
153. 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
154. Which one is NOT a reserved keyword?
Answers:
• switch
• extern
• intern
• struct
• static
155. Function Overloading is not supported in C.
Answers:
• False
• True
156. #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
157. 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.
158. 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.
159. 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
160. Will this loop terminate? int x=10; while( x-- > 0 );
Answers:
• no
• It will not compile
• It will cause segfault
• yes
161. How can you access the first element of an array called 'arr'?
Answers:
• arr[0]
• *arr
• (both of these)
162. What will be the output?  void main() {       int const*p=9;       printf("%d",++(*p)); }
Answers:
• 10
• Compiler Error
• 9
163. 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
164. 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
165. 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
166. What is the value of 1 & 2?
Answers:
• 3
• 1
• 0
• 2
167. With:  sizeof(char *) == 4  sizeof(char) == 1   What will sizeof(plop) for char plop[2][3] be?
Answers:
• 6
• 10
• 18
• 14
168. foo[4] is equivalent of :
Answers:
• *(&foo + 4)
• &(foo + 4)
• (*foo + 4)
• There is no equivalent using those notations
• *(foo + 4)
169. 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.
170. 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
171. 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
172. stdarg.h defines?
Answers:
• array definitions
• arguments with data types
• formal arguments
• actual arguments
• macros used with variable argument functions
173. What does malloc(0) return?
Answers:
• The program segfault
• The behavior is implementation-defined
• NULL
• A unique pointer
174. 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
175. Which one is not a bitwise operator ?
Answers:
• <<
• ~
• !
• |
• ^
176. 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
177. 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
178. 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.
179. 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
180. 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
181. Which of the following data type is scalar?
Answers:
• Float
• Array
• Pointer
• Union
182. memmove() is safer than memcpy()
Answers:
• False
• True
183. 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.
184. 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
185. For a 3 dimensions array[2][3][4] how many call to malloc do you need at least?
Answers:
• 1
• 2
• 3
• 4
• 24
186. 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.
187. 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.
188. #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
189. 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.
190. with  sizeof(char) == 1 sizeof(char *) == 4  char *a, *b; a = b; b++; What is (b - a)?
Answers:
• It segfaults
• 1
• 4
• It depends
191. 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
192. What is the value of i after : int i; i = 10; i = i++ + i++;
Answers:
• 23
• 22
• 20
• It's implementation dependent
• 21
193. #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
194. 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
195. 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
196. 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; };
197. #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
198. Which command-line flag will dump the output of the preprocessor from gcc?
Answers:
• --preprocessing
• -H
• -E
• -C
199. 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
200. 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

201. Does "gcc -Wall" print all warnings?
Answers:
• Yes
• No
• It depends
202. What does "11 | 4 == 15" evaluate to?
Answers:
• 11
• 15
• 0
• 1
203. 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.
204. 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
205. The end of a C statement is indicated by this character.
Answers:
• +
• .
• ;
• :
206. 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
207. What will be the output?  void main() {       int const *p = 9;       printf("%d", ++(*p)); }
Answers:
• Compiler Error
• 10
• 9
• Runtime error
208. 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
209. void main() { char  *a; a="1234"; printf("%d",sizeof(a)); }
Answers:
• 2 bytes
• 4 bytes
• 1 bytes
• garbage value
• size not defined
210. 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
211. Which statement do you use to stop loop processing without a condition?
Answers:
• continue;
• jump;
• break;
212. Which keyword is needed to compile a method in Csharp which uses pointers?
Answers:
• void
• static
• unsafe
213. 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.
214. 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.
215. 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
216. Which statement is a convenient way to iterate over items in an array?
Answers:
• foreach
• for
• switch
217. Given the following C# statement:   int[] myInts = { 5, 10, 15 };  What is the value of myInts[1]?
Answers:
• 15
• 5
• 10
218. Which classes are provided in C# for writing an XML file?
Answers:
• XMLReader
• XMLWriter
• XMLCreation
219. The keyword used to include libraries/namespaces in C# is:
Answers:
• using
• use
• include
• import
220. 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.
221. Which C# debugging tools are available to you with Visual Studio?
Answers:
• Stepping through your code
• Breakpoints
• All of these
222. 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();
223. 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
224. The manifest of a C# assembly contains...
Answers:
• supported locales.
• version information.
• all of these
225. The default value of a reference type is...
Answers:
• null
• none of these
• 0
• unknown
226. C# support what types of inheritance.
Answers:
• All options.
• Interface inheritance
• Implementation inheritance
227. Which of the following is not a built-in data type in C#?
Answers:
• int
• single
• bool
• string
228. 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;
229. Choose the types of members which you can have in your C# class?
Answers:
• fields
• methods
• constructors
• all of these
230. 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.
231. 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
232. 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#
233. CSharp cannot be run without installing...
Answers:
• the Java Virtual Machine.
• the Common Language Runtime.
• all .NET languages.
234. 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
235. Valid parameter types for Indexers in C# are...
Answers:
• enum
• integer
• all of these
• string
236. Which option below is an Operator?
Answers:
• Binary
• All Options
• Ternary
• Unary
237. Where would you find the definition for the Stack<T> class?
Answers:
• System.Collections.Generic namespace
• System.Collections.Specialized namespace
• System.Data namespace
238. 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
239. An Indexer in C# allows you to index a
Answers:
• Both class and struct
• class
• struct
240. Which keyword would be used in a class declaration to stop the class from being inherited?
Answers:
• sealed
• static
• extern
• out
241. What is the keyword to create a condition in a switch statement that handles unspecified cases?
Answers:
• if(...)
• finally
• default
• standard
• else(...)
242. 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
243. 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
244. 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
245. 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.
246. 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.
247. What is the full name of the base type of all the types in .NET?
Answers:
• System.object
• Object
• System
• System.Object
• object
248. 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
249. 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
250. An interface contains signatures only for
Answers:
• all of these
• methods
• properties
• events
• indexers
251. 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.
252. 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.
253. Which classes are provided in C# for navigating through an XML file?
Answers:
• Both XMLDocument and XMLReader
• XMLReader
• None of these
• XMLDocument
254. 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
255. 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
256. You can attach a handler to an event by using which operator?
Answers:
• +=
• ++
• =
• ->
• =>
257. 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.
258. 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
259. 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.
260. 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
261. 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)
262. Which of the following is not a C# keyword?
Answers:
• as
• of
• is
• if
• in
263. 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
264. 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.
265. 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.
266. 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.
267. Csharp provides an XML documentation comment syntax by prefacing your comment lines with...
Answers:
• ///
• /*
• //
268. 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() { }
269. In the following array instantiation:  string[] names = new string[2]; , how many items can the array hold?
Answers:
• 3
• 2
• 1
• 0
270. 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
271. 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
272. 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.
273. What is: #if ?
Answers:
• Compiler option
• Preprocessor directive
• Invalid syntax
• Condition
274. 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
275. 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.
276. In order for the following to compile:  using (CustomClass = new CustomClass()) {  }   CustomClass needs to implement which interface?
Answers:
• ICustomAdapter
• Disposable
• IUsing
• IDisposable
• IMemoryManagement
277. When dealing with currency calculations you should always use what data type?
Answers:
• Int
• Int32
• Decimal
• Float
• Double
278. 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.
279. 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.
280. 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();
281. 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
282. 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.
283. Anonymous functions can see the local variables of the sourrounding methods.
Answers:
• False.
• True.
284. In CSharp, what is the default member accessibility for a class?
Answers:
• public
• protected
• private
285. 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
286. Converting a value type to reference type is called....
Answers:
• Compilation
• Street magic
• Unboxing
• Typecasting
• Boxing
287. 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.
288. C# is an object oriented language which does not offer...
Answers:
• simple types.
• global variables.
• classes.
289. Which line is required in your Csharp application in order to use the StringBuilder class?
Answers:
• using System.Strings
• using System.Text;
• using System;
290. 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
291. 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.
292. 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.
293. 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.
294. 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.
295. 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.
296. A struct can inherit from another struct or class.
Answers:
• False
• True
297. 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
298. 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
299. 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
300. 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.


301. 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.
302. Which is an example of a C# main method?
Answers:
• all of these
• static void Main()
• none of these
• static int main()
303. 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
304. 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()
305. Which C# statement is equivalent to this:  int myInt = new int(); ?
Answers:
• int myInt = NULL;
• int myInt = 0;
• int myInt;
306. 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.
307. 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(...)
308. 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();
309. Which of the following is NOT a value type?
Answers:
• System.Boolean
• System.String
• System.DateTime
• System.Int32
• System.Char
310. 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
311. 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
312. 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#
313. 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.
314. 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
315. Which of the following is NOT reference type?
Answers:
• System.Exception
• System.Drawing.Point
• System.Type
• System.String
316. 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
317. 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
318. Default DateTime.MinValue is  "1/1/0001 12:00:00 AM"
Answers:
• False
• True
319. What namespaces are necessary to create a localized application?
Answers:
• System.Resources, System.Localization.
• System.Globalization, System.Resources.
• System.Data, System.Resources.
320. Which are not function members in a C# class?
Answers:
• Indexers
• Fields
• Destructors
• Events
• Operators
321. 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#
322. 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
323. Interfaces in C# cannot contain:
Answers:
• indexers
• implementation of methods
• all of the answers are correct
• events
324. 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
325. 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
326. 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
327. 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
328. 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
329. 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
330. True or False: We can create a sealed abstract class in c#.
Answers:
• True
• False
331. 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
332. 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
333. The main reflection methods to query attributes are contained in the...
Answers:
• System.Reflection.MemberInfo class
• System.Reflection.GetCustomAttributes
• System.Collections.Attributes
334. 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#.
335. 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,
336. 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)
337. 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.
338. 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
339. 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
340. 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
341. 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).
342. Given code:  var foo = 7; var bar = ++foo + foo++;  what is the value of bar?
Answers:
• 14
• 15
• 18
• 17
• 16
343. [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;
344. 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
345. 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
346. What is the output of Console.WriteLine(10L / 3 == 10d / 3);?
Answers:
• False
• True
• Nothing, you will get a compiler error
347. 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)"
348. 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
349. 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.
350. 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
351. 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.
352. 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;
353. 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)
354. 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
355. 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.
356. 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.
357. 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
358. In C#, a subroutine is called a ________.
Answers:
• Managed Code
• Method
• Metadata
• Function
359. 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.
360. 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.
361. True or false: A class can implement multiple interfaces
Answers:
• False
• True
362. What are the access modifiers available in C#?
Answers:
• protected, internal, private
• public, protected, internal, private
• public, private
• public, internal, private
• public, protected, private
363. 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
364. 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.
365. 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"
366. 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
367. 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
368. 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
369. 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
370. 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
371. 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.
372. 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
373. 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.
374. 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
375. 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.
376. 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
377. 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"
378. 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
379. How many generations does the garbage collector in .NET employ?
Answers:
• 2
• 5
• 3
• 1
• 4
380. 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
381. 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
382. 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
383. 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
384. 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
385. 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
386. 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
387. 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.
388. 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)"
389. 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)
390. 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.
391. 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;
392. In the following variable definition, if declared inside a function body, what is the initial value of result:  int result; ?
Answers:
• 0
• NULL
• undefined
393. 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)
394. 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
395. 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);
396. What does OOD stand for?
Answers:
• Overly Objective Design
• Object-Oriented Design
• Object-oriented database
• Operating on Objects in Design
397. 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.
398. 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.
399. What is the value of a = 11 % 3;?
Answers:
• 3
• 1
• 0
• 2
400. What is the value of i after the following statement(s)?  int i (4.36);
Answers:
• 4.4
• 5
• 4.36
• 4

401. int, long, double and string can all be described as:
Answers:
• Constructors
• Attributes
• Class members
• Data Types
402. Which of the following is not a loop structure?
Answers:
• do while loop
• stop when loop
• for loop
403. The C++ programming language derived from:
Answers:
• C
• French
• Fortran
• Basic
404. C++ statements are separated by this symbol:
Answers:
• Colon (:)
• Semi-colon (;)
• Hash symbol (#)
• Addition sign (+)
405. The statement i += 5; has the same meaning as:
Answers:
• i == i;
• 5 += 1;
• i = i + 5;
• i * 5++;
406. Which of the following is not a fundamental data type in C++?
Answers:
• bool
• char
• wide
407. Which of the following operators below allow you to define the member functions of a class outside the class?
Answers:
• ,
• ?
• :%
• ::
408. 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
409. 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)
410. Which of the following is not a C++ primitive type?
Answers:
• int
• double
• float
• real
411. How do you declare an integer variable x in C++?
Answers:
• int x;
• x int;
• x is integer;
• declare x as integer;
• int<x>;
412. Which of the following is a reserved word in C++?
Answers:
• Char
• char
• CHAR
• character
413. Which of the following is a valid variable declaration statement?
Answers:
• int a, b, c;
• int a:
• int a; b; c;
414. The output of this program is  int main () { cout << "Hello World!"; return 0; }
Answers:
• Hello World
• Hello World!
• 0
• Syntax error
415. 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.
416. An ordered and indexed sequence of values is an:
Answers:
• Class
• List of Parameters
• Group
• Array
417. In C++, a single line comment needs to be begun with
Answers:
• a leading //.
• a leading /**.
• all of these
418. Choose the function declaration which you would use if you did not need to return any value.
Answers:
• myfunction(void)
• void myfunction()
• myfunction()
419. This symbol calls the pre-processor to include the specified system files such as iostream.
Answers:
• Exclamation Mark (!)
• Hash Symbol (#)
• Ampersand (&)
• Forward Slash (/)
420. 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
421. Which is a valid comment statement in C++?
Answers:
• // this is a comment
• /* this is a comment */
• Both of these
422. A C++ program begins its execution at the
Answers:
• none of these
• main function.
• function specified by the preprocessor.
423. 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.
424. Which statement assigns to variable a the address of variable b?
Answers:
• a = b;
• a = *b;
• a = &b;
425. 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.
426. 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.
427. What does operator+ perform on two instances of std::string?
Answers:
• none of these
• String concatenation
• Nothing
• Address addition
428. 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
429. What is the size in bytes of an int variable on a 32-bit system?
Answers:
• 2
• 3
• 1
• 4
430. How would you declare a pointer which has no type in C++?
Answers:
• int * data;
• null * data;
• void data;
• void * data;
431. 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.
432. The printmsg function does not require any arguments.  Choose the statement which calls the function.
Answers:
• printmsg;
• printmsg();
• void printmsg();
433. 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)
434. 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.");
435. What is an advantage to using C++ Templates?
Answers:
• reduce code duplication
• templates are typesafe
• all of these
• increase code flexibility
436. Can constructors be overloaded?
Answers:
• Depends on the situation.
• No
• Yes
437. std::make_heap() converts a range into a heap and std::sort_heap() turns a heap into a sorted sequence.
Answers:
• true
• false
438. 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)
439. 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
440. 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
441. 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
442. Consider this code fragment:  a = 25;  b = &a;   What does b equal?
Answers:
• address of a
• value contained in the address of a
• 25
443. Consider this code fragment:  a = 25;  b = &a;   What does b equal?
Answers:
• address of a
• value contained in the address of a
• 25
444. 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.
445. True or False: In C++, a comment can only be specified with a leading //.
Answers:
• True
• False
446. 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
447. The dynamic memory requested by C++ programs is allocated...
Answers:
• from high memory.
• from the memory heap.
• from extended memory.
• from the memory stack.
448. 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
449. 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.
450. 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);
451. 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.
452. 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);
453. What does the following create:  int * p; p=0;?
Answers:
• Void pointer
• Both Null and Void
• Neither Null nor Void
• Null pointer
454. 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
455. Which of the following is a valid variable identifier in C++?
Answers:
• class
• m_test
• 1_str
456. 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.
457. 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.
458. What is the value of  7 == 5+2 ? 4 : 3?
Answers:
• 7
• 4
• 3
459. What is the value of 2--2?
Answers:
• Nothing, that is not a valid C++ expression.
• 2
• 0
• 4
• -2
460. 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
461. 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()
462. 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.
463. 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
464. 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.
465. 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.
466. What does the following statement return:  int a(0);  cout << typeid(a).name();
Answers:
• int
• NULL
• 0
467. What does the following statement return:  int a(0);  cout << typeid(a).name();
Answers:
• int
• NULL
• 0
468. Can a struct have a constructor in C++?
Answers:
• No. Struct types do not support member functions.
• No. Only class types allow constructors.
• Yes.
469. In the following variable definition, what is the initial value of result:  int result; ?
Answers:
• 0
• undefined
• NULL
470. 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.
471. 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.
472. 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
473. What are the two valid boolean (bool) values in C++?
Answers:
• TRUE and FALSE
• true and false
• True and False
474. Which is a valid variable initialization statement?
Answers:
• Both of these are valid
• int a = 0;
• int a(0);
475. What is the size of the character array which would hold the value "Helloo"?
Answers:
• 6
• 8
• 7
476. 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.
477. What is the data type for the following: L"Hello World"?
Answers:
• a string
• an integer string
• a wide character string
478. 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.
479. 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.
480. True or False: A class that has a pure virtual method can be instantiated.
Answers:
• True
• False
481. 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)
482. 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
483. 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
484. 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.
485. 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
486. 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
487. int *array = new int[10]; delete array;
Answers:
• This code will correctly free memory
• This code has undefined behavior

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



No comments:

Post a Comment