140 practice MCQs covering exactly what Sasken's assessment tests — C, C++, Data Structures & Algorithms, and Operating Systems, at medium-to-hard difficulty. Each question is collapsed by default with the answer and explanation hidden underneath — try answering first, then tap to reveal.

Section 1: C Programming

30 questions — medium to hard

1. What does the following print? int x = 5; printf("%d %d %d", x++, x++, x);

  1. 5 6 7
  2. 7 6 5
  3. Undefined behavior
  4. 5 5 5
Reveal Answer

✅ Answer: c) Undefined behavior. Order of evaluation of function arguments is unspecified in C, and modifying x more than once without a sequence point causes UB.

2. sizeof(char *) on a 64-bit system is typically:

  1. 1 byte
  2. 4 bytes
  3. 8 bytes
  4. Depends on data type pointed to
Reveal Answer

✅ Answer: c) 8 bytes. All pointer types have the same size on a given architecture (8 bytes on 64-bit), regardless of what they point to.

3. Which storage class retains a variable's value between function calls?

  1. auto
  2. register
  3. static
  4. extern
Reveal Answer

✅ Answer: c) static. static local variables are allocated once and persist for the program's lifetime, retaining their value across calls.

4. What is the output? #define SQUARE(x) x*x int a = 25 / SQUARE(5); printf("%d", a);

  1. 1
  2. 25
  3. 5
  4. 0
Reveal Answer

✅ Answer: b) 25. Macro expands to 25 / 5*5 = (25/5)*5 = 5*5 = 25, due to lack of parentheses — classic macro pitfall.

5. Which function correctly resizes previously allocated memory?

  1. malloc()
  2. calloc()
  3. realloc()
  4. alloc()
Reveal Answer

✅ Answer: c) realloc(). realloc() resizes a previously allocated block, preserving existing content up to the smaller of old/new size.

6. What does int *p = (int*)0; represent?

  1. Compile error
  2. Null pointer
  3. Pointer to 0th array index
  4. Garbage pointer
Reveal Answer

✅ Answer: b) Null pointer. Assigning the integer constant 0 to a pointer creates a null pointer, valid in C for representing "points to nothing."

7. Output of the following? int arr[5] = {1,2,3,4,5}; printf("%d", *(arr+2));

  1. Address of arr[2]
  2. 3
  3. 2
  4. Error
Reveal Answer

✅ Answer: b) 3. arr+2 points to arr[2]; dereferencing gives its value, 3. Array name decays to pointer to first element.

8. Which is true about const int *p?

  1. p cannot change
  2. *p cannot change via p
  3. Both p and *p are constant
  4. Neither is constant
Reveal Answer

✅ Answer: b) *p cannot change via p. const int *p means p points to a constant int — the pointed-to value can't be modified through p, but p itself can be reassigned.

9. What's the size of struct A { char c; int i; }; on a typical 32-bit-aligned system?

  1. 5 bytes
  2. 8 bytes
  3. 6 bytes
  4. 4 bytes
Reveal Answer

✅ Answer: b) 8 bytes. Padding is added after char (3 bytes) so int starts at a 4-byte aligned address — structure alignment/padding rule.

10. What does the volatile keyword indicate to the compiler?

  1. Variable is read-only
  2. Variable's value may change unexpectedly (e.g. hardware/interrupt)
  3. Variable is thread-local
  4. Variable is a constant
Reveal Answer

✅ Answer: b) Variable's value may change unexpectedly. volatile prevents compiler optimizations that assume the value doesn't change outside program flow, common in embedded/hardware register access.