Computer Science MCQs · C++ and Object-Oriented Programming What is the purpose of declaring a member function virtual in C++? A To stop derived classes from redefining it B To force the function to be inlined everywhere C To hide the function from other translation units D To allow dispatch at runtime through a base pointer Correct answer MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming The subscript expression a[i] is defined as equivalent to which form? A a + i B *(a + i) Correct answer C *(a + i * 4) D &a[i] MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What does typedef do when applied to a struct name? A It allocates memory for the type B It makes every member static C It blocks copying of the struct D It creates an alias for the type Correct answer MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What value does the expression 10 > 5 > 1 produce in C? A 1 B 2 C 3 D 0 Correct answer MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming Why does getchar return a value of type int? A To allow it to read wide characters B To make it faster than putchar C So that EOF can be told apart from data Correct answer D Because characters are stored as int MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What is the result of calling free twice on the same pointer? A The block is simply released again B A compile-time error in every compiler C The pointer is set to NULL for you D Undefined behaviour and possible heap damage Correct answer MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What does strcpy copy into the destination buffer? A Only the source characters, no null B At most n characters from the source C The address of the source string D The source characters and its null byte Correct answer MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What restriction applies to the case labels of a switch in C? A They must be listed in ascending order B They must be integer constant expressions Correct answer C They must be distinct string literals D They must be variables of type int MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What does the declaration int (*f)(int); declare? A A pointer to a function taking an int Correct answer B A function that returns an int pointer C An array of pointers to functions D A pointer to an array of int values MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming Which value does the C standard guarantee for sizeof(char)? A 4 B 8 C 1 Correct answer D 2 MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming How does calloc differ from malloc? A calloc leaves the block uninitialised B calloc zero-fills the allocated block Correct answer C calloc places the block on the stack D calloc resizes an existing block MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming For a non-NULL result, what does the C standard guarantee about the pointer returned by malloc? A It stays valid until the enclosing block ends B It is aligned for any type with a fundamental alignment Correct answer C It points into the current function's stack frame D It is zero-filled before it is handed back MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming With #define SQUARE(x) x*x, what does SQUARE(2 + 3) evaluate to? A 13 B 10 C 11 Correct answer D 25 MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming In C99 and later, what does the expression -7 / 2 evaluate to? A -3 Correct answer B -4 C -3.5 D 3 MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming A char pointer is set to point at a string literal. What happens if the program writes through that pointer? A A compile-time error is reported B The literal is copied before writing C The write is silently discarded D The behaviour is undefined Correct answer MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What value does strlen return for the string literal "hello"? A 4 B 7 C 5 Correct answer D 6 MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What does a break statement do inside a loop? A It leaves the innermost enclosing loop Correct answer B It skips only the current iteration C It terminates the whole program at once D It restarts the loop from the beginning MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming Which conversion specifier should scanf use to read a double? A %lf Correct answer B %f C %d D %.2f MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What does strcmp return when its two arguments are equal strings? A Null B True C Zero Correct answer D False MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming With int a[4] = {5, 10, 15, 20}; what does *(a + 3) - *(a + 1) evaluate to? A 10 Correct answer B 5 C 15 D 20 MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What happens if a function returns the address of one of its local variables? A The compiler promotes the variable to global B The program stops with a runtime error C Using that pointer is undefined behaviour Correct answer D The value is moved to the heap automatically MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming What is special about a static local variable declared inside a function? A It is stored in the caller's frame B It becomes visible in other files C It is reset on every function entry D It retains its value between calls Correct answer MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming In an expression, what does the name of an array decay into? A A pointer to its first element Correct answer B A pointer to its last element C A copy of the entire array D The count of its elements MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming For char s[] = "hello"; what does sizeof s evaluate to? A 7 B 4 C 6 Correct answer D 5 MCQSEXAM Show answer Read explanation
Computer Science MCQs · C Programming Given int x = 7, what value does the expression x / 2 * 2 produce? A 3 B 6 Correct answer C 7 D 8 MCQSEXAM Show answer Read explanation