Question:* Which of the following is not a predefined variable type?
Answer: • real
Question:* 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; }
Answer: • a=22 b=24
Question:* What is i after the following block of code is executed : int i; i = 10/5/2/1;
Answer: • 1
Question:* In C, a block is defined by...
Answer: • curly braces
Question:* Is C Object Oriented?
Answer: • No
Question:* int *a, b; What is b ?
Answer: • An int
Question:* which of these is not valid keyword?
Answer: • var
Question:* Which of the following is the correct operator to compare two integer variables?
Answer: • ==
Question:* What is the only function all C programs must contain?
Answer: • main()
Question:* Which of the following special symbols are allowed in a variable name?
Answer: • _ (underscore)
Question:* int i = 17 / 3; what is the value of i ?
Answer: • 5
Question:* In C language, && is a
Answer: • Logical operator
Question:* What is the value of the variable x? int x; x = 32 / 64;
Answer: • 0
Question:* What does "int *p = malloc(2);" do?
Answer: • It will make p point to an uninitialized two-byte piece of memory allocated from the heap.
Question:* A C variable can start with a digit as well a letter.
Answer: • False
Question:* What will be the output of: #include <stdio.h> void main() { char a[6] = "Hello"; printf("%d", sizeof(a)); }
Answer: • 6
Question:* int tab[3] = {0,1,2}; int i = 0; tab[++i] == ?
Answer: • 1
Question:* How can you make an infinite loop in C?
Answer: • All answers are right.
Question:* If we pass an array as an argument of a function, what exactly get passed?
Answer: • Address of array
Question:* Which one is NOT a reserved keyword?
Answer: • intern
Question:* Function Overloading is not supported in C.
Answer: • True
Question:* #ifdef __APPLE__ # include <dir/x.h> #else # include <other_dir/x.h> #endif What does it mean?
Answer: • It will include dir/x.h if __APPLE__ is defined, or other_dir/x.h, otherwise.
Question:* In C ...
Answer: • Strings are surrounded with double quotes, and Character with single-quotes.
Question:* 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)); }
Answer: • It depends on the compiler and the hardware architecture.
Question:* What are the different types of floating-point data in C ?
Answer: • float, double, long double
Question:* Will this loop terminate? int x=10; while( x-- > 0 );
Answer: • yes
Question:* What is the value of p in int a,b,*p; p=&a; b=**p; printf("%d",p);
Answer: • address of variable a
Question:* How can you access the first element of an array called 'arr'?
Answer: • (both of these)
Question:* What will be the output? void main() { int const*p=9; printf("%d",++(*p)); }
Answer: • Compiler Error
Question:* Which statement is true about double?
Answer: • its size depends on the implementation
Question:* 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); }
Answer: • 65 56
Question:* char* buf[100]; strcpy(buf, argv[1]); Which security risk is this code vulnerable to?
Answer: • Stack overflow
Question:* What is the value of 1 & 2?
Answer: • 0
Question:* With: sizeof(char *) == 4 sizeof(char) == 1 What will sizeof(plop) for char plop[2][3] be?
Answer: • 6
Question:* What is the output of the following code? char * str1 = "abcd"; char * str2 = "xyz"; if( str1 < str2 ) printf( "1" ); else printf( "2" );
Answer: • Undefined
Question:* foo[4] is equivalent of :
Answer: • *(foo + 4)
Question:* What will the following code print? void *p = malloc(0); printf ("%d\n", p);
Answer: • Unknown, it depends on what malloc will return.
Question:* To send an array as a parameter to function, which one is a right way:
Answer: • doThis(array)
Question:* What will this code print out? #include <stdio.h> void function(char *name) { name=NULL; } main() { char *name="ELANCE"; function(name); printf("%s",name); }
Answer: • ELANCE
Question:* What is the output of printf("%d\n", sizeof(long) / sizeof(int))?
Answer: • Completely unknown, it depends on the implementation.
Question:* stdarg.h defines?
Answer: • macros used with variable argument functions
Question:* What does malloc(0) return?
Answer: • The behavior is implementation-defined
Question:* Predict the output :: main() { float a = 1; switch(a) { case 1 : printf("Hi"); case 1.0 : printf("Hello"); default : printf("Default"); break; } }
Answer: • Error, float can't be used in switch
Question:* struct mystruct { int a; float b; }; struct mystruct *ptr; Which of these expressions will access member a?
Answer: • (*ptr).a;
Question:* Which one is not a bitwise operator ?
Answer: • !
Question:* What does the following do? int j = 10; while (j --> 0){ printf("%d ", j); }printf("\n");
Answer: • 9 8 7 6 5 4 3 2 1 0
Question:* 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; }
Answer: • 64
Question:* 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 );
Answer: • Abcd Abcd
Question:* What will be the output? main() { float a=1.1; double b=1.1; if(a==b) printf("True"); else printf("False"); }
Answer: • Normally False, but could be True depending on implementation.
Question:* What is meaning of following declaration? int(*p[3])();
Answer: • p is array of pointers to functions
Question:* 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));
Answer: • 1 0
Question:* Which of the following data type is scalar?
Answer: • Float
Question:* The main() function can be called recursively.
Answer: • True
Question:* Sort these integer constants from smallest to largest.
Answer: • 040, 40, 0x40
Question:* #include <stdio.h> #define FUNC(A,B) #B#A int main() { printf(FUNC(AA,BB)); } What does it print?
Answer: • BBAA
Question:* int a = 1, b; a = 1 & b = 2; what's the result of a and b?
Answer: • It doesn't compile.
Question:* memmove() is safer than memcpy()
Answer: • True
Question:* What will be the output? #include <stdio.h> int main() { char c = 125; c = c + 10; printf("%d", c); return 0; }
Answer: • It is implementation dependent.
Question:* What is the difference between fopen and open?
Answer: • fopen opens a stream which is buffered.
Question:* 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); }
Answer: • 4 3
Question:* For a 3 dimensions array[2][3][4] how many call to malloc do you need at least?
Answer: • 1
Question:* Currently, what does GCC stand for?
Answer: • GNU Compiler Collection
Question:* What is the difference between "void foo();" and "void foo(void);"?
Answer: • void foo() can take any arguments while void foo(void) can take none.
Question:* Is this code valid in C89? #define RED "\033[31m" #define END "\033[0m" puts("Hello " RED "world" END " !");
Answer: • Yes
Question:* What is the output of the following program: #include "stdio.h" int main( ) { printf( "%d %d", sizeof(" "),sizeof(NULL) ); return 0; }
Answer: • None of these
Question:* Which one is a reserved keyword?
Answer: • restrict
Question:* #include <stdio.h> int main() { int n; n = 2, 4, 6; printf("%d", n); return 0; } what is the output?
Answer: • 2
Question:* What is the output of the Program : main() { int i,j; i=1,2,3; j=(1,2,3); printf("%d %d",i,j); }
Answer: • 1 3
Question:* 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; }
Answer: • 6
Question:* What does this code do? printf("%u", -08);
Answer: • It doesn't even compile.
Question:* with sizeof(char) == 1 sizeof(char *) == 4 char *a, *b; a = b; b++; What is (b - a)?
Answer: • 1
Question:* 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; }
Answer: • 6
Question:* #include<stdio.h> int main(){ char *string="smarterer"; printf("%d",printf("%s",string)); return 0; } What is the output?
Answer: • smarterer9
Question:* What is the output: register int n; printf("%u",&n);
Answer: • compile time error
Question:* What is the value of i after : int i; i = 10; i = i++ + i++;
Answer: • It's implementation dependent
Question:* #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); }
Answer: • y is 49
Question:* 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); }
Answer: • Z=18
Question:* 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); }
Answer: • 1, 0, 10, 0
Question:* Which of these is NOT correct syntax?
Answer: • struct { int a; float b; };
Question:* #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?
Answer: • 1, -1
Question:* Which command-line flag will dump the output of the preprocessor from gcc?
Answer: • -E
Question:* int a=2, b=3, c=4; int res; res=c>b>a; What is the value of res?
Answer: • 0
Question:* After char *foo = calloc(1, 2); what is the value of *foo?
Answer: • 0
Question:* Does "gcc -Wall" print all warnings?
Answer: • No
Question:* What does "11 | 4 == 15" evaluate to?
Answer: • 11
Question:* What will the following code print? void *p = malloc(0); printf ("%d\n", *p);
Answer: • Nothing, it won't compile.
Question:* The system function longjmp() can be used to return execution control to any user-specified point in the active function call tree.
Answer: • True
Question:* The end of a C statement is indicated by this character.
Answer: • ;
Question:* What is the output of printf("%d\n", sizeof(long) / sizeof(int))?
Answer: • Depends on the implementation, but always some number >= 1.
Question:* What will be the output? void main() { int const *p = 9; printf("%d", ++(*p)); }
Answer: • Compiler Error
Question:* What is the difference between "void foo();" and "void foo(void);" in C?
Answer: • void foo() allows for calls with any number of arguments while void foo(void) does not allow for calls with any arguments.
Question:* This code will: void main() { char const *p = "abcdef"; printf("%s",*(p+4)); }
Answer: • cause an error when run
Question:* void main() { char *a; a="1234"; printf("%d",sizeof(a)); }
Answer: • 2 bytes
Question:* What will be the output of this code? #include <stdio.h> int main(void) { int i = 1; printf("%d", i+++i); return 0; }
Answer: • 2
Question:* Which statement do you use to stop loop processing without a condition?
Answer: • break;
Question:* Which keyword is needed to compile a method in Csharp which uses pointers?
Answer: • unsafe
Question:* What is the purpose of the ref keyword in C#?
Answer: • It allows you to pass a parameter to a method by reference instead of by value.
Question:* Which of the following describes a C# interface?
Answer: • An interface contains only the signatures of methods, delegates or events.
Question:* Which of the following is an example of an auto implemented property?
Answer: • public string Name { get; set; }
Question:* Classes that can be used for reading / writing files like TextReader, StreamWriter, File can be found in which namespace?
Answer: • System.IO
Question:* Which statement is a convenient way to iterate over items in an array?
Answer: • foreach
Question:* What type of memory management does Csharp employ?
Answer: • managed
Question:* Given the following C# statement: int[] myInts = { 5, 10, 15 }; What is the value of myInts[1]?
Answer: • 10
Question:* Which classes are provided in C# for writing an XML file?
Answer: • XMLWriter
Question:* The keyword used to include libraries/namespaces in C# is:
Answer: • using
Question:* The purpose of the curly braces, { and }, in C#:
Answer: • is to mark the beginning and end of a logical block of code.
Question:* Which C# debugging tools are available to you with Visual Studio?
Answer: • All of these
Question:* If your Csharp class is called Cats, which statement creates an object of type Cats?
Answer: • Cats myCat = new Cats();
Question:* Csharp provides a built in XML parser. What line is needed to use this feature?
Answer: • using System.Xml;
Question:* Exceptions can be handled in Csharp with a...
Answer: • try catch finally block
Question:* The manifest of a C# assembly contains...
Answer: • all of these
Question:* The default value of a reference type is...
Answer: • null
Question:* C# support what types of inheritance.
Answer: • All options.
Question:* Which of the following is not a built-in data type in C#?
Answer: • single
Question:* In order to create a filestream object in C#, what do you need to include in your program?
Answer: • using System.IO;
Question:* Exceptions can be handled in C# with a...
Answer: • try catch finally block
Question:* Choose the types of members which you can have in your C# class?
Answer: • all of these
Question:* A sealed class in C# means:
Answer: • that the class cannot be used for inheritance.
Question:* The Code Document Object Model can be used for...
Answer: • all of these
Question:* The foreach loop in C# is constructed as:
Answer: • foreach (int i in collection)
Question:* CSharp cannot be run without installing...
Answer: • the Common Language Runtime.
Question:* In C#, what would you use to output the contents of a variable to the screen?
Answer: • Console.Write() method
Question:* What is the result of the following expression? int x = 100 / 0;
Answer: • The system will throw a DivideByZeroException more info
Question:* Valid parameter types for Indexers in C# are...
Answer: • all of these
Question:* What is the purpose of the following statement: ~myClass() ?
Answer: • It is the destructor for myClass instances.
Question:* Which option below is an Operator?
Answer: • All Options
Question:* Where would you find the definition for the Stack<T> class?
Answer: • System.Collections.Generic namespace
Question:* What do the following two lines of code demonstrate: string Substring (int startIndex) string Substring (int startIndex, int length) ?
Answer: • method overloading
Question:* An Indexer in C# allows you to index a
Answer: • Both class and struct
Question:* Which keyword would be used in a class declaration to stop the class from being inherited?
Answer: • sealed
Question:* What is the keyword to create a condition in a switch statement that handles unspecified cases?
Answer: • default
Question:* Which class provides the best basic thread creation and management mechanism for most tasks in Csharp?
Answer: • System.Threading.ThreadPool
Question:* A static class in C# can only contain...
Answer: • static members
Question:* Given the following statement: public enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }. What is the value of Monday?
Answer: • 0
Question:* bool test = true; string result = test ? "abc" : "def"; What is the value of result after execution?
Answer: • abc
Question:* What does if((number <= 10) && (number >= 0)) evaluate to if number is -6?
Answer: • False
Question:* The C# statement: using System; means...
Answer: • import the collection of classes in the System namespace.
Question:* If you know that a method will need to be redefined in a derived class,
Answer: • you should declare it as virtual in the base class.
Question:* What is the full name of the base type of all the types in .NET?
Answer: • System.Object
Question:* Which of the following best describes this class definition? : public class Foo<T> {}
Answer: • It is a generic class
Question:* What is the full name of the type that is represented by keyword int?
Answer: • System.Int32
Question:* An interface contains signatures only for
Answer: • all of these
Question:* What is a jagged array in C#?
Answer: • A multi-dimensional array with dimensions of various sizes.
Question:* When the protected modifier is used on a class member,
Answer: • the member can be accessed by derived class instances.
Question:* Which classes are provided in C# for navigating through an XML file?
Answer: • Both XMLDocument and XMLReader
Question:* Reflection is used to...
Answer: • all of these
Question:* Given: var foo = 7%2; what is the value of foo?
Answer: • 1
Question:* If you are overloading methods in a class the methods must have...
Answer: • the same name.
Question:* You can attach a handler to an event by using which operator?
Answer: • +=
Question:* Which attribute specifies a method to run after serialization occurs?
Answer: • OnSerialized
Question:* In C# the System.String.Format method is used for ....
Answer: • Replacing the format item in a specified string with the string representation of a corresponding object.
Question:* Can you change the value of a variable while debugging a C# application?
Answer: • Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.
Question:* During the class definition, inheritance in C# is acomplished by putting which of the following:
Answer: • ":" sign
Question:* What is unique about an abstract class in C#?
Answer: • You cannot create an instance of it.
Question:* In C#, methods with variable number of arguments:
Answer: • can be created using the "params" keyword in argument list
Question:* How do you catch an exception indicating that you are accessing data outside of the bounds of the array?
Answer: • catch(IndexOutOfRangeException ex)
Question:* Which of the following is not a C# keyword?
Answer: • of
Question:* Which of the following declares your Csharp class as an attribute?
Answer: • public class myAttribute : System.Attribute
Question:* The extern keyword is used to declare a method which is...
Answer: • implemented externally.
Question:* When the public modifier is used on a class,
Answer: • the class can be accessed by external dll's.
Question:* A struct differs from a class in C#
Answer: • in that a struct stores the value not a reference to the value.
Question:* Csharp provides an XML documentation comment syntax by prefacing your comment lines with...
Answer: • ///
Question:* How do you implement your own version of ToString() method in your class?
Answer: • public override string ToString() { }
Question:* C# provides an XML documentation comment syntax by prefacing your comment lines with...
Answer: • ///
Question:* What does the following statement do?: DateTime? startDate;
Answer: • allows you to set the variable startDate equal to null
Question:* In the following array instantiation: string[] names = new string[2]; , how many items can the array hold?
Answer: • 2
Question:* While handling an exception, "finally" block:
Answer: • all of the answers are correct
Question:* From which class do you need to derive to implement a custom attribute?
Answer: • System.Attribute
Question:* Can you use pointers to manipulate memory in C#?
Answer: • Yes, but only by using the unsafe keyword.
Question:* What is: #if ?
Answer: • Preprocessor directive
Question:* Extension methods in C#...
Answer: • all of the answers are correct
Question:* A difference between a struct and a class is that...
Answer: • a struct acts like a value type.
Question:* C# code is compiled in...
Answer: • Common Intermediate Language, compiled in CPU-specific native code the first time it's executed.
Question:* In order for the following to compile: using (CustomClass = new CustomClass()) { } CustomClass needs to implement which interface?
Answer: • IDisposable
Question:* When dealing with currency calculations you should always use what data type?
Answer: • Decimal
Question:* Applications written in C# require the .NET framework...
Answer: • to be installed on the machine running the application.
Question:* 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?
Answer: • "a string"
Question:* If your C# class is a static class called OutputClass, which contains public static void printMsg();, how would you call printMsg?
Answer: • OutputClass.printMsg();
Question:* In C#, if you would like to create a class across multiple files, you should precede the class definition with...
Answer: • the partial keyword
Question:* In a Windows Forms application, the static void Main must have a [STAThread] attribute. What does it mean?
Answer: • The [STAThread] marks a thread to use the Single-Threaded COM Apartment.
Question:* Anonymous functions can see the local variables of the sourrounding methods.
Answer: • True.
Question:* What is the default visibility for members of classes and structs in C#?
Answer: • private
Question:* 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?
Answer: • Compiler error - parameter arrays must be the last parameter specified.
Question:* In CSharp, what is the default member accessibility for a class?
Answer: • private
Question:* Which keyword would be used in the class definition if we did not want to create an instance of that class?
Answer: • static
Question:* Converting a value type to reference type is called....
Answer: • Boxing
Question:* What happens with the following lines? #region Debug [block of code HERE] #endregion
Answer: • You can visually expand or collapse the block of code.
Question:* Which of the following statements about static constructors are true?
Answer: • All answers are correct
Question:* C# is an object oriented language which does not offer...
Answer: • global variables.
Question:* Which line is required in your Csharp application in order to use the StringBuilder class?
Answer: • using System.Text;
Question:* 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?
Answer: • Attribute
Question:* What does the following statement do? #error Type Mismatch
Answer: • Generates a compiler error.
Question:* What's the best practice for enumerating all the values of a Suit enum?
Answer: • foreach (Suit suit in Enum.GetValues(typeof(Suit))) { }
Question:* 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.
Answer: • True.
Question:* The built-in string class in C# provides an immutable object which means...
Answer: • that the value of the string object can be set only once.
Question:* In the following statement: string[] words = text.Split(delimiterChars); what is the function of delimiterChars?
Answer: • Contains an array of characters which are to be used to delimit the string.
Question:* A struct can inherit from another struct or class.
Answer: • False
Question:* What description BEST suites the code below. var Dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
Answer: • We're creating a case insensitive string dictionary
Question:* 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?
Answer: • 2
Question:* Proper way of defining an extension method for a string class in C# is:
Answer: • public static int WordCount(this String str)
Question:* How do you declare a generic method that takes one parameter which must be a value type?
Answer: • public void Test<T>(T t) where T : struct { ... }
Question:* What does the params method keyword do?
Answer: • Allows a variable number of parameters to be used when a method is called.
Question:* Consider the following C# code: int x = 123; if (x) { Console.Write("The value of x is nonzero."); } What happens when it is executed?
Answer: • It is invalid in C#.
Question:* Which is an example of a C# main method?
Answer: • static void Main()
Question:* int[] myArray = new int[10]; What will be the value of myArray[1]?
Answer: • 0
Question:* Consider the following statement: string str = "abcdefg";. How would get the length of str?
Answer: • int strlength = str.Length;
Question:* Which C# statement is equivalent to this: int myInt = new int(); ?
Answer: • int myInt = 0;
Question:* What does the Obsolete attribute do when used in conjunction with a class?
Answer: • It generates an error/warning when the class is used.
Question:* Will the following code compile? public class CustomClass : IDisposable { }
Answer: • No
Question:* What will be the output of the following C# code: int num = 1; Console.WriteLine(NUM.ToString());
Answer: • Compile time error
Question:* The primary expression for initializing an anonymous object in C# is in the form of:
Answer: • new {...}
Question:* 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?
Answer: • B b= new A();
Question:* Which of the following is NOT a value type?
Answer: • System.String
Question:* 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"); } }
Answer: • Make foo volatile
Question:* You need to create a custom Dictionary class, which is type safe. Which code segment should you use?
Answer: • public class MyDictionary : Dictionary<string, string>
Question:* What is the purpose of [Flags] attribute?
Answer: • Allow values combination for enumeration (enums)
Question:* What is the main difference between ref and out parameters when being passed to a method?
Answer: • "out" parameters don't have to be initialised before passing to a method, whereas "ref" parameters do.
Question:* A static member of a class is:
Answer: • Shared by all instances of a class.
Question:* 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?
Answer: • public int CompareTo(string other)
Question:* In C#, "implicit" keyword is used to:
Answer: • create user-defined type conversion operator that will not have to be called explicitly
Question:* Which of the following is NOT reference type?
Answer: • System.Drawing.Point
Question:* What are the access modifiers available in C#?
Answer: • private, protected, public, internal, protected internal
Question:* In C#, "explicit" keyword is used to:
Answer: • create user-defined type conversion operator that must be invoked with a cast
Question:* Default DateTime.MinValue is "1/1/0001 12:00:00 AM"
Answer: • True
Question:* What namespaces are necessary to create a localized application?
Answer: • System.Globalization, System.Resources.
Question:* Which are not function members in a C# class?
Answer: • Fields
Question:* Are bool and Boolean equivalent?
Answer: • Yes
Question:* 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?
Answer: • StringComparison
Question:* Interfaces in C# cannot contain:
Answer: • implementation of methods
Question:* void Main() { int x = 1000000; double d = checked(x*x); Console.WriteLine("{0:N}",d); } The execution result will be:
Answer: • A System.OverflowException will be thrown
Question:* In C# "new" keyword is used to...
Answer: • All of the answers are correct
Question:* How many string objects are created in this piece of code: string first = "tick"; string second = first + "tech"; second += "fly";
Answer: • 3
Question:* 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?
Answer: • A
Question:* What is wrong with this code: public enum @enum : ushort { Item1 = 4096, Item2 = 8192, Item3 = 16384, Item4 = 32768, Item5 = 65536, }
Answer: • Constant value '65536' cannot be converted to a 'ushort'
Question:* 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>(); }
Answer: • All the answers
Question:* 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?
Answer: • B
Question:* True or False: We can create a sealed abstract class in c#.
Answer: • False
Question:* 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
Answer: • False
Question:* Which answer is not a valid C# 4.0 variable definition?
Answer: • int[][] d = new int[1, 2];
Question:* In C#, difference between "new" and "override" is:
Answer: • "new" explicitly hides a member inherited from a base class
Question:* The main reflection methods to query attributes are contained in the...
Answer: • System.Reflection.MemberInfo class
Question:* C# provides Finalize methods as well as destructors, unlike Java. Which of the following is true about it?
Answer: • Finalize method cannot be directly implemented, however it is implicitly called by destructor, which can.
Question:* Which of the following will set the process return code to 1?
Answer: • Environment.ExitCode = 1
Question:* In C#, what is the difference between: "int[,] arrayName;" and "int[][] arrayName;"
Answer: • "int[,] arrayName;" is multidimensional array, while "int[][] arrayName;" is jagged array (array of arrays)
Question:* interface ICat{ void Meow(); } class Robot:ICat { void ICat.Meow() {} } void Main() { Robot robot = new Robot(); robot.Meow(); } This code is an example of:
Answer: • Explicit interface member implementation, with invalid method call.
Question:* What does the @ symbol do when used in C# code?
Answer: • Both stops string literal escape sequences being processed and allows you to use reserved keywords as variable names.
Question:* What is the result of following function? public bool SomeTest(){ return "i like c#".ToUpper().Equals("I LIKE C#"); }
Answer: • Either true or false, depending on the current culture
Question:* What is the expected output? static void Main() { object o = -10.3f; int i = (int)o; Console.WriteLine(i); }
Answer: • Runtime exception (InvalidCastException)
Question:* enum Score { Awful, Soso, Cancode } Given the enum above, which statement(s) will generate a compiler error?
Answer: • Score soso = 1;
Question:* Given code: var foo = 7; var bar = ++foo + foo++; what is the value of bar?
Answer: • 16
Question:* [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?
Answer: • workingDays &= ~Days.WeekEnd;
Question:* Given the following code: var result = 7/2; what will be the value of result?
Answer: • 3
Question:* 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 ?
Answer: • Compilation error
Question:* What is the output of Console.WriteLine(10L / 3 == 10d / 3);?
Answer: • False
Question:* 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:
Answer: • "M:DocGen.Skills`1.Test(`0)"
Question:* In the context of (A | B) and (A || B), the (A || B) boolean evaluation is known as what?
Answer: • A "short-circuit" evaluation
Question:* Given the C# syntax for a method, attributes modifiers return-type method-name(parameters ), what does the attribute [Conditional("DEBUG")] on a method indicate?
Answer: • The method can only execute if the program has defined DEBUG.
Question:* When can you assign a value to a readonly field?
Answer: • Both of these
Question:* What is the size of a long on a 32 bit operating system in C#?
Answer: • Signed 64 bit integer
Question:* void Disagree(ref bool? maybe) { maybe = maybe ?? true ? false : maybe; } When calling this method, the value of the reference parameter will be changed to:
Answer: • false.
Question:* Does return 10 as long; compile?
Answer: • No, because long is not a reference or nullable type
Question:* Which of these is NOT a way to create an int array?
Answer: • var a = new int[];
Question:* Can multiple catch blocks be executed?
Answer: • No, once the proper catch code fires off, the control is transferred to the finally block (if there are any)
Question:* If A = true and B = false, how does [1.] (A | B) differ from [2.] (A || B)
Answer: • In [1.], B will be evaluated, in [2.] it won't be.
Question:* If you would like to create a read-only property in your C# class:
Answer: • Do not implement a set method.
Question:* What does the following statement do: delegate double Doubler(double x); ?
Answer: • Creates a type for the method Doubler.
Question:* Consider the following C# code: int x = 123; if (x) { Console.Write("The value of x is nonzero."); } What happens when it is executed?
Answer: • It is invalid in C#.
Question:* The [Flags] attribute indicates that an enum is to be used as a bit field. However, the compiler does not enforce this.
Answer: • true
Question:* In C#, a subroutine is called a ________.
Answer: • Method
Question:* Reflection is used to...
Answer: • all of these
Question:* When the public modifier is used on a class,
Answer: • the class can be accessed by external dll's.
Question:* True or false: A class can implement multiple interfaces
Answer: • True
Question:* What are the access modifiers available in C#?
Answer: • public, protected, internal, private
Question:* bool test = true; string result = test ? "abc" : "def"; What is the value of result after execution?
Answer: • abc
Question:* Can you change the value of a variable while debugging a C# application?
Answer: • Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.
Question:* Given the following statement: public enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }. What is the value of Monday?
Answer: • 0
Question:* In C#, methods with variable number of arguments:
Answer: • can be created using the "params" keyword in argument list
Question:* During the class definition, inheritance in C# is acomplished by putting which of the following:
Answer: • ":" sign
Question:* The following line of code in C#: IEnumerable<int> aList = new List<int>();
Answer: • Legal
Question:* C# code is compiled in...
Answer: • Common Intermediate Language, compiled in CPU-specific native code the first time it's executed.
Question:* What is the purpose of the [STAThread] attribute?
Answer: • The [STAThread] marks a thread to use the Single-Threaded COM Apartment.
Question:* What is the result of the following code? var a = 3; a = "hello"; var b = a; Console.WriteLine(b);
Answer: • A compilation error
Question:* 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?
Answer: • "a string"
Question:* What description BEST suites the code below. var Dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
Answer: • We're creating a case insensitive string dictionary
Question:* What is the main difference between ref and out parameters when being passed to a method?
Answer: • "out" parameters don't have to be initialised before passing to a method, whereas "ref" parameters do.
Question:* Are bool and Boolean equivalent?
Answer: • Yes
Question:* 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?
Answer: • Compiler error - parameter arrays must be the last parameter specified.
Question:* In C#, "explicit" keyword is used to:
Answer: • create user-defined type conversion operator that must be invoked with a cast
Question:* What does the following code do? string a = "hello"; string b = null; string c = a + b; Console.WriteLine(c);
Answer: • It outputs "hello"
Question:* In C#, "implicit" keyword is used to:
Answer: • create user-defined type conversion operator that will not have to be called explicitly
Question:* How many generations does the garbage collector in .NET employ?
Answer: • 3
Question:* What is wrong with this code: public enum @enum : ushort { Item1 = 4096, Item2 = 8192, Item3 = 16384, Item4 = 32768, Item5 = 65536, }
Answer: • Constant value '65536' cannot be converted to a 'ushort'
Question:* 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?
Answer: • A
Question:* In C#, difference between "new" and "override" is:
Answer: • "new" explicitly hides a member inherited from a base class
Question:* 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");
Answer: • world
Question:* In C#, what is the difference between: "int[,] arrayName;" and "int[][] arrayName;"
Answer: • "int[,] arrayName;" is multidimensional array, while "int[][] arrayName;" is jagged array (array of arrays)
Question:* Given the following code: var result = 7/2; what will be the value of result?
Answer: • 3
Question:* In the context of (A | B) and (A || B), the (A || B) boolean evaluation is known as what?
Answer: • A "short-circuit" evaluation
Question:* What is the value of Status.TiredAndHungry? public enum Status { Unknown = 0, Sick = 1, Tired = 2, Hungry = 4, TiredAndHungry = Tired | Hungry }
Answer: • 6
Question:* 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>(); }
Answer: • All the answers
Question:* C# provides Finalize methods as well as destructors, unlike Java. Which of the following is true about it?
Answer: • Finalize method cannot be directly implemented, however it is implicitly called by destructor, which can.
Question:* 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?
Answer: • B
Question:* If A = true and B = false, how does [1.] (A | B) differ from [2.] (A || B)
Answer: • In [1.], B will be evaluated, in [2.] it won't be.
Question:* 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:
Answer: • "M:DocGen.Skills`1.Test(`0)"
Question:* Choose the valid C++ function declaration which passes the function parameters by reference.
Answer: • void myFunction (int& a, int& b, int& c)
Question:* Which is a requirement when using overloaded C++ functions?
Answer: • Argument lists for the overloaded functions must be different.
Question:* What is the difference between a class and a struct
Answer: • The members of a class are private by default, and the members of a struct are public by default.
Question:* Which of the following statements assigns the hexadecimal value of 75 to a literal constant?
Answer: • const int a = 0x4b;
Question:* In the following variable definition, if declared inside a function body, what is the initial value of result: int result; ?
Answer: • undefined
Question:* String literals can extend to more than a single line of code by putting which character at the end of each unfinished line?
Answer: • a backslash (\)
Question:* 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; } }
Answer: • 3
Question:* 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.
Answer: • In header: extern std::atomic<int> x; In source: std::atomic<int> x(20);
Question:* What will be the output? auto fn = [](unsigned char a){ cout << std::hex << (int)a << endl; }; fn(-1);
Answer: • ff
Question:* What does OOD stand for?
Answer: • Object-Oriented Design
Question:* std::vector<int> foo {5}; (assume C++11)
Answer: • Initializes a vector with 1 element of the value 5.
Question:* Classes can contain static member variables which are global to the class and...
Answer: • can be accessed by all objects of the same class.
Question:* What is the value of a = 11 % 3;?
Answer: • 2
Question:* What is the value of i after the following statement(s)? int i (4.36);
Answer: • 4
Question:* int, long, double and string can all be described as:
Answer: • Data Types
Question:* Which of the following is not a loop structure?
Answer: • stop when loop
Question:* The C++ programming language derived from:
Answer: • C
Question:* C++ statements are separated by this symbol:
Answer: • Semi-colon (;)
Question:* Which two variables are the same?
Answer: • test and test
Question:* The statement i += 5; has the same meaning as:
Answer: • i = i + 5;
Question:* Which of the following is not a fundamental data type in C++?
Answer: • wide
Question:* Which of the following operators below allow you to define the member functions of a class outside the class?
Answer: • ::
Question:* What is taking place in this statement: x == y;
Answer: • x and y are being checked for equality
Question:* Which of the following is a valid C++ function declaration which does not return a value?
Answer: • void myFunction( int a, int b)
Question:* Which of the following is not a C++ primitive type?
Answer: • real
Question:* How do you declare an integer variable x in C++?
Answer: • int x;
Question:* Which of the following is a reserved word in C++?
Answer: • char
Question:* Which of the following is a valid variable declaration statement?
Answer: • int a, b, c;
Question:* The output of this program is int main () { cout << "Hello World!"; return 0; }
Answer: • Hello World!
Question:* If you have two different C++ functions which have the same name but different parameter types, it is called...
Answer: • function overloading.
Question:* An ordered and indexed sequence of values is an:
Answer: • Array
Question:* In C++, a single line comment needs to be begun with
Answer: • a leading //.
Question:* Choose the function declaration which you would use if you did not need to return any value.
Answer: • void myfunction()
Question:* This symbol calls the pre-processor to include the specified system files such as iostream.
Answer: • Hash Symbol (#)
Question:* The process of making one variable appear to be another type of data is called TYPECASTING. The two processes are:
Answer: • Explicit and Implicit
Question:* Which is a valid comment statement in C++?
Answer: • Both of these
Question:* A C++ program begins its execution at the
Answer: • main function.
Question:* What does the following statement do: std::cout << x;?
Answer: • Writes the contents of x to stdout.
Question:* Which statement assigns to variable a the address of variable b?
Answer: • a = &b;
Question:* 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...
Answer: • within the body of a function or block.
Question:* In the following line of C++ code, int foo[50]; what does the number 50 represent?
Answer: • The number of integer elements the array shall hold.
Question:* What does operator+ perform on two instances of std::string?
Answer: • String concatenation
Question:* 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.
Answer: • True
Question:* What is the size in bytes of an int variable on a 32-bit system?
Answer: • 4
Question:* How would you declare a pointer which has no type in C++?
Answer: • void * data;
Question:* What does the following statement mean? const int a = 50;
Answer: • The value of a cannot change from 50.
Question:* The printmsg function does not require any arguments. Choose the statement which calls the function.
Answer: • printmsg();
Question:* Choose the statement which declares a function with a default value for an argument.
Answer: • void myfunction(int a=2)
Question:* 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."?
Answer: • if( (sum == 10) && (total < 20) )printf("incorrect.");
Question:* What is an advantage to using C++ Templates?
Answer: • all of these
Question:* Can constructors be overloaded?
Answer: • Yes
Question:* True or False: A void pointer is a special type of pointer which indicates the absence of a type for the pointer.
Answer: • True
Question:* std::make_heap() converts a range into a heap and std::sort_heap() turns a heap into a sorted sequence.
Answer: • true
Question:* Choose the statement which declares a function with arguments passed by reference.
Answer: • void myfunction(int& a, int& b)
Question:* Consider the following: namespace myNamespace { int a; int b; } How would the main part of the program access myNamespace variable a?
Answer: • myNamespace::a
Question:* What does the sizeof(arg) operator do?
Answer: • returns the size in bytes of arg
Question:* What does the sizeof(arg) operator do?
Answer: • returns the size in bytes of arg
Question:* Consider this code fragment: a = 25; b = &a; What does b equal?
Answer: • address of a
Question:* Consider this code fragment: a = 25; b = &a; What does b equal?
Answer: • address of a
Question:* Which of the following statements assigns the hexadecimal value of 75 to a literal constant?
Answer: • const int a = 0x4b;
Question:* What will "int a = 'a';" do?
Answer: • It will declare a new variable a and set it to 97 (assuming a machine that uses ASCII).
Question:* True or False: In C++, a comment can only be specified with a leading //.
Answer: • False
Question:* Given the following code sample: catch(…) { cout << "exception";}. What do the ellipses indicate?
Answer: • The handler will catch any type of error thrown.
Question:* Why would you use the preprocessor directive #include <iostream> in your C++ program?
Answer: • Your program uses cout function calls.
Question:* The dynamic memory requested by C++ programs is allocated...
Answer: • from the memory heap.
Question:* 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?
Answer: • myItem->units
Question:* What is the right way to place an opening curly bracket in C++?
Answer: • There is no C++ rule about placing curly brackets.
Question:* Which is(are) an example(s) of valid C++ function prototype(s)?
Answer: • all of these
Question:* What does "int *p; p = 0;" do?
Answer: • It sets p to nullptr.
Question:* If you have an external function which needs access to private and protected members of a class, you would specify the function as...
Answer: • friend myClass myFunction(myClass);
Question:* What does the following create: int * p; p=0;?
Answer: • Null pointer
Question:* What's the difference between an array and a vector?
Answer: • Vectors can be dynamically resized, but an array's size is fixed
Question:* Which of the following is a valid variable identifier in C++?
Answer: • m_test
Question:* What does the line: #include <iostream> mean in a C++ program?
Answer: • It tells the preprocessor to include the iostream standard file.
Question:* char * array = "Hello"; char array[] = "Hello"; What is the difference between the above two, if any, when using sizeof operator ?
Answer: • 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.
Question:* What is the value of 7 == 5+2 ? 4 : 3?
Answer: • 4
Question:* What is the value of 2--2?
Answer: • Nothing, that is not a valid C++ expression.
Question:* If your C++ program produces a memory leak, what could be a cause of the leak?
Answer: • Dynamically allocated memory has not been freed.
Question:* 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();
Answer: • B::x()
Question:* The default access level assigned to members of a class is...
Answer: • private
Question:* Which of the following is not a specific type casting operator in the C++ language?
Answer: • unknown_cast
Question:* Defined data types (typedef) allow you to create...
Answer: • alternate names for existing types in C++.
Question:* Which of the following can cause a memory corruption error?
Answer: • All of these
Question:* What is the difference between classes and structures?
Answer: • Elements of a class are private by default
Question:* Within a class declaration, the statement "virtual int foo() = 0;" does what?
Answer: • Declares a pure virtual function.
Question:* What does: #ifdef WIN32 tell the preprocessor to do?
Answer: • If the preprocessor directive WIN32 is defined, executed any statements following until a #endif statement is encountered.
Question:* What does the following statement return: int a(0); cout << typeid(a).name();
Answer: • int
Question:* What does the following statement return: int a(0); cout << typeid(a).name();
Answer: • int
Question:* Can a struct have a constructor in C++?
Answer: • Yes.
Question:* In the following variable definition, what is the initial value of result: int result; ?
Answer: • undefined
Question:* The following code sample demonstrates which form of type conversion? short a(200); int b; b=a;
Answer: • Implicit conversion
Question:* Which of these is a difference between struct and class types?
Answer: • Structs are public-inherited by default. Classes are private-inherited by default.
Question:* std::vector<int> foo(5);
Answer: • Initializes a vector with 5 elements of value 0.
Question:* A section of code designed to perform a specific job on data of predetermined type and size can be defined as:
Answer: • Function
Question:* What are the two valid boolean (bool) values in C++?
Answer: • true and false
Question:* Which is a valid variable initialization statement?
Answer: • Both of these are valid
Question:* What is the guaranteed complexity of std::push_heap?
Answer: • O(log(n))
Question:* What is the size of the character array which would hold the value "Helloo"?
Answer: • 7
Question:* A void pointer is a special type of pointer which indicates the...
Answer: • absence of a type for the pointer.
Question:* What is the data type for the following: L"Hello World"?
Answer: • a wide character string
Question:* Where does the compiler first look for file.h in the following directive: #include "file.h" ?
Answer: • The same directory that includes the file containing the directive.
Question:* In C++, what is the difference between these two declarations: void foo(); void foo(void);
Answer: • None, they are equivalent.
Question:* True or False: A class that has a pure virtual method can be instantiated.
Answer: • False
Question:* What is the time complexity of delete the first variable in a deque object (e.g., deque<int> a;)?
Answer: • O(1)
Question:* Which class(es) can be used to perform both input and output on files in C++?
Answer: • fstream
Question:* class A { int x; protected: int y; public: int z; }; class B: public A { }; What is the privacy level of B::y?
Answer: • protected
Question:* Define a way other than using the keyword inline to make a function inline
Answer: • The function must be defined inside the class.
Question:* Per the C++11 standard, what does the following statement mean? std::vector<int> vecInt{5};
Answer: • 'vecInt' container has one element, whose value is 5
Question:* class A { int x; protected: int y; public: int z; }; class B: private A { }; What is the privacy level of B::z?
Answer: • private
Question:* int *array = new int[10]; delete array;
Answer: • This code has undefined behavior
Question:* Suppose int * a = new int[3]; How would you deallocate the memory block pointed by a?
Answer: • delete[] a;
Question:* String literals can extend to more than a single line of code by putting which character at the end of each unfinished line?
Answer: • a backslash (\)
Question:* In order to execute this statement, string mystring = "This is a string";, which statement is needed prior to this in your program?
Answer: • Both of the other answers are correct.
Question:* When should the class Foo have a virtual destructor?
Answer: • When Foo is designed to be subclassed
Question:* Which of the following is a potential side-effect of inlining functions?
Answer: • The size of the compiled binary increases
Question:* What is a virtual function in C++?
Answer: • A class member function that you expect to be redefined in derived classes.
Question:* What of the following is not permitted in a pure virtual class in C++?
Answer: • All of these are permitted.
Question:* Which of the following rules apply to operator overloading in C++?
Answer: • Both of the other answers are correct.
Question:* Which of the following calls method foo() from the parent class Parent of the current class?
Answer: • Parent::foo();
Question:* What is the value of x after the following code: int x = 0; if (x = 1) { x = 2; } else { x = 1; }
Answer: • 2
Question:* What is the data range for an unsigned integer value in C++ on a system where ints are 32 bits?
Answer: • 0 to 4,294,967,295
Question:* int a[] {1, 2, 3}; a[[] { return 2; }()] += 2; What is the value of a[2]?
Answer: • Compile error: malformed attribute.
Question:* What does the "explicit" keyword do?
Answer: • It prevents a single-argument constructor from being used in an implicit conversion
Question:* What is the purpose of std::set_union?
Answer: • Constructs a sorted union of the elements from two ranges.
Question:* Given the following, how many bytes of memory does var occupy?: class a { int x; short y; }; a var[20];
Answer: • Depends
Question:* Given: union a { int x; short y; }; a var[20]; How many bytes of memory does var occupy?
Answer: • Depends
Question:* What is the below code? struct code { unsigned int x: 4; unsigned int y: 4; };
Answer: • A bit field structure declaration.
Question:* Is the following legal C++ code? | char *str = "abc" + "def";
Answer: • No.
Question:* In the code below: void foo(){ static int x=10; } When is x created?
Answer: • At the first call of foo().
Question:* Which of the following is not a member of std::weak_ptr<T>?
Answer: • weak_ptr(T *r) noexcept;
Question:* class A { int x; protected: int y; public: int z; }; class B: public virtual A { }; What is the privacy level of B::x?
Answer: • B does not inherit access to x from A.
Question:* If you do not supply any constructors for your class, which constructor(s) will be created by the compiler?
Answer: • Both of these
Question:* 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; }
Answer: • Yes.
Question:* What is the proper way to use the .substr() function on the following string to get the word "World"? string aString = "Hello World!";
Answer: • aString.substr(6,5);
Question:* Which is NOT a valid hash table provided by the STL?
Answer: • hash_table
Question:* 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?
Answer: • public
Question:* What will be the output? auto fn = [](unsigned char a){ cout << std::hex << (int)a << endl; }; fn(-1);
Answer: • ff
Question:* An anonymous namespace is used to...
Answer: • prevent external access to declarations local to a compilation unit
Question:* Which function always returns an rvalue reference from "x", which can be used to indicate the object is going to be destroyed soon?
Answer: • std::move(x)
Question:* According to the C++ standard, what is sizeof(void)?
Answer: • Nothing, void doesn't have a size.
Question:* Where T is a type: std::vector<T>::at vs std::vector<T>::operator[]:
Answer: • at is always bounds checked. operator[] is not.
Question:* 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; } }
Answer: • 3
Question:* std::deque<int> queue; queue.push_back(1); int& ref = queue.back(); queue.push_back(2); Where does ref point to?
Answer: • Front of the queue
Question:* How do you declare a pointer where the memory location being pointed to cannot be altered, but the value being pointed to can?
Answer: • int * const x = &y;
Question:* What type of exceptions can the following function throw: int myfunction (int a);?
Answer: • All
Question:* 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(); }
Answer: • foo
Question:* signed int a = 5; unsigned char b = -5; unsigned int c = a > b; What is the value of c?
Answer: • 0
Question:* The value of "(sizeof(short) == sizeof(int) && sizeof(int) == sizeof(long))" is
Answer: • implementation defined
Question:* Is the following well-formatted C++ code? %:include <vector> int main (void) <% std::vector<int> ivec <% 1, 2, 3 }; ??>
Answer: • Yes, it will compile.
Question:* 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.
Answer: • false true true
Question:* What is the type being defined here: typedef A (B::*C)(D, E) const;
Answer: • C is defined to be a constant member function pointer of class B taking arguments of types D and E, returning type A.
Question:* const std::string * s; std::string const * g; What can be said about s and g?
Answer: • both s and g are modifiable pointers to an immutable string
Question:* According to the IEEE standard, which of the following will always evaluate to true if the value of "var" is NaN?
Answer: • var != var
Question:* int C++; What is the value of C now?
Answer: • This is invalid code in C++
Question:* Which operator cannot be overloaded by a class member function?
Answer: • ?
Question:* If sizeof(int)==4 what is sizeof(long)?
Answer: • At least 4
Question:* 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.
Answer: • void my_lock::lock() { int exp(1); while (!data.compare_exchange_strong(exp, 0)) exp = 1; }
Question:* According to the C++11 standard, which of these is a keyword?
Answer: • char32_t
Question:* 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; }
Answer: • Always "ab"
Question:* Which of the following operators can you not overload?
Answer: • . (dot)
Question:* If we have a class myClass , what can we say about the code: myClass::~myClass(){ delete this; this = NULL; }
Answer: • It won't compile
Question:* What is the value of bar(1) in: int foo(int &x) { return ++x; } int bar(int x) { x += foo(x); return x; }
Answer: • 4
Question:* What is the difference between: int a(0); and int a = 0; ?
Answer: • None
Question:* Is it possible to create class instance placed at a particular location in memory?
Answer: • Yes, placement new does this.
Question:* 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?
Answer: • Any one of the specified choices fixes compilation error
Question:* What is the value of "v"? auto &p = 10; double v = p;
Answer: • compilation error
Question:* If after: a* var = new a(); var's value is 0x000C45710 What is its value after: delete var;
Answer: • 0x000C45710
Question:* What does "int *p = malloc(2);" do?
Answer: • Nothing, it will yield a type mismatch compiler error.
Question:* 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; }
Answer: • Always "g h f "
Question:* What will a declaration such as “extern "C" char foo(int);” do?
Answer: • It ensures that foo's mangled link name matches that of the C compiler so it can be called from C functions.
Question:* int* a = {1, 2, 3}; | Where are the 1,2,3 values stored?
Answer: • This code is not valid C++
Question:* What does operator -> () do?
Answer: • Defines the structure dereference operator for a class
Question:* What can we say about: myClass::foo(){ delete this; } .. void func(){ myClass *a = new myClass(); a->foo(); }
Answer: • None of these.
Question:* Can a static member function be declared as const?
Answer: • No
Question:* double a = 1.0; double *p = &a; a = a/*p; Which of the following statements about the code is true?
Answer: • /* means the start of comments.
Question:* Virtual inheritance is needed...
Answer: • to not get multiple ambiguous copies of members of ancestor classes
Question:* What type of exceptions will the following function throw: int myfunction (int a) throw();?
Answer: • None
Question:* What is the value of (false - ~0)?
Answer: • 1
Question:* What is the effect of "const" following a member function's parameter declarations?
Answer: • The function may be called on a const qualified object, and treats the object as const qualified.
Question:* int a = 001 + 010 + 100; What is the value of a?
Answer: • 109
Question:* class foo { foo(){}; }; class boo : public foo { boo() : foo() {}; }; which standard allows compilation of this code.
Answer: • none, the code wont compile
Question:* In C++ the three STL (Standard Template Library) container adapters are:
Answer: • stack, queue, priority_queue
Question:* Identifying classes by their standard typedefs, which of the following is NOT declared by the standard C++ library?
Answer: • istream & istream::operator >> ( streambuf & )
Question:* What is the value of 10.10 % 3?
No comments:
Post a Comment