C Programming Interview Questions and Answers

C questions that campus tests and embedded-company interviews ask again and again, with clear answers. Includes predict-the-output questions on pointers, strings and recursion.

  1. Q1. What does the & operator give when used as &x?

    • A. A copy of x
    • B. The value of x
    • C. x multiplied by itself
    • D. The address of x
    Show answer

    Answer: D. The address of x
    &x is the memory address of x, which is why scanf needs &x to write into it.

  2. Q2. Which header file declares printf() and scanf()?

    • A. conio.h
    • B. stdlib.h
    • C. string.h
    • D. stdio.h
    Show answer

    Answer: D. stdio.h
    stdio.h is the standard input/output header.

  3. Q3. What character ends every C string?

    • A. '\n'
    • B. '\0' (the null character)
    • C. A space
    • D. '$'
    Show answer

    Answer: B. '\0' (the null character)
    C strings are char arrays terminated by '\0'; strlen counts up to it.

  4. Q4. Which function allocates memory on the heap?

    • A. malloc()
    • B. alloc()
    • C. new()
    • D. sizeof()
    Show answer

    Answer: A. malloc()
    malloc returns a pointer to a heap block (or NULL); release it with free().

  5. Q5. What happens if you forget to free() memory you malloc'd?

    • A. Nothing ever
    • B. A memory leak
    • C. The program crashes immediately
    • D. A compile error
    Show answer

    Answer: B. A memory leak
    The memory stays reserved until the program ends.

  6. Q6. Which format specifier prints a double with printf?

    • A. %f
    • B. %d
    • C. %c
    • D. %s
    Show answer

    Answer: A. %f
    %f (or %lf) prints floating-point values; scanf needs %lf for a double.

  7. Q7. What is a pointer?

    • A. A variable that stores a memory address
    • B. A function that points to code
    • C. A keyword for loops
    • D. A special type of array
    Show answer

    Answer: A. A variable that stores a memory address
    int *p = &x; stores the address of x in p.

  8. Q8. What is the difference between a struct and a union?

    • A. A union's members share the same memory
    • B. A struct can't hold arrays
    • C. A union can't hold ints
    • D. There is no difference
    Show answer

    Answer: A. A union's members share the same memory
    A struct gives each member its own space; a union overlaps them, so its size is that of the largest member.

  9. Q9. Which loop always runs its body at least once?

    • A. do-while
    • B. for
    • C. while
    • D. None of them
    Show answer

    Answer: A. do-while
    do { } while (cond); checks the condition after the body.

  10. Q10. What is the value of an uninitialised local int in C?

    • A. NULL
    • B. Unpredictable (garbage)
    • C. 0
    • D. -1
    Show answer

    Answer: B. Unpredictable (garbage)
    Local variables are not initialised automatically; globals and statics start at 0.

  11. Q11. Which keyword keeps a local variable's value between function calls?

    • A. extern
    • B. register
    • C. static
    • D. const
    Show answer

    Answer: C. static
    A static local is created once and keeps its value across calls.

  12. Q12. What does strcmp(a, b) return when the strings are equal?

    • A. -1
    • B. 1
    • C. 0
    • D. true
    Show answer

    Answer: C. 0
    strcmp returns 0 for equal strings, negative if a < b and positive if a > b.

  13. Q13. Why can't you compare two strings with == in C?

    • A. It only compares the first character
    • B. It compares addresses, not contents
    • C. It always returns true
    • D. It is a syntax error
    Show answer

    Answer: B. It compares addresses, not contents
    Array names decay to pointers; use strcmp to compare the text.

  14. Q14. What is a dangling pointer?

    • A. A pointer to a function
    • B. A pointer to memory that has already been freed
    • C. A pointer to a pointer
    • D. A pointer that is NULL
    Show answer

    Answer: B. A pointer to memory that has already been freed
    Using it is undefined behaviour; set pointers to NULL after free().

  15. Q15. How are arrays passed to functions in C?

    • A. As a full copy
    • B. They can't be passed
    • C. By value of the last element
    • D. As a pointer to the first element
    Show answer

    Answer: D. As a pointer to the first element
    So the function can change the caller's array, and sizeof inside the function gives the pointer size.

  16. Q16. What does the preprocessor directive #define PI 3.14 do?

    • A. Creates a variable named PI
    • B. Imports a maths library
    • C. Declares a function PI
    • D. Replaces PI with 3.14 before compilation
    Show answer

    Answer: D. Replaces PI with 3.14 before compilation
    Macros are text substitutions done by the preprocessor.

  17. Q17. Which operator accesses a struct member through a pointer?

    • A. ::
    • B. ->
    • C. .
    • D. &
    Show answer

    Answer: B. ->
    p->x is shorthand for (*p).x.

  18. Q18. What is the size of a char in C?

    • A. 1 byte
    • B. 2 bytes
    • C. 4 bytes
    • D. Depends on the string
    Show answer

    Answer: A. 1 byte
    sizeof(char) is always 1 by definition.

  19. Q19. What does recursion need so it doesn't run forever?

    • A. A global variable
    • B. A pointer
    • C. A while loop
    • D. A base case
    Show answer

    Answer: D. A base case
    Without a base case the calls never stop and the stack overflows.

  20. Q20. What does calloc() do differently from malloc()?

    • A. It sets the allocated memory to zero
    • B. It allocates on the stack
    • C. It frees memory
    • D. It resizes memory
    Show answer

    Answer: A. It sets the allocated memory to zero
    calloc(n, size) allocates n * size bytes and zeroes them.

  21. Q21. What does this code print?

    int a = 5, b = 2;
    printf("%d\n", a / b);
    • A. 3
    • B. 2
    • C. 2.5
    • D. 2.000000
    Show answer

    Answer: B. 2
    Integer division of two ints drops the fraction.

  22. Q22. What does this code print?

    int a = 5, b = 2;
    printf("%.2f\n", (double) a / b);
    • A. 2.00
    • B. 2.5
    • C. 2.50
    • D. 2
    Show answer

    Answer: C. 2.50
    Casting a to double makes the division happen in floating point.

  23. Q23. What does this code print?

    int x = 5;
    int y = ++x;
    printf("%d %d\n", y, x);
    • A. 6 5
    • B. 5 6
    • C. 5 5
    • D. 6 6
    Show answer

    Answer: D. 6 6
    ++x increments first, so y gets 6 and x is 6.

  24. Q24. What does this code print?

    #include <stdio.h>
    
    void set(int *p) { *p = 20; }
    
    int main() {
        int x = 10;
        set(&x);
        printf("%d\n", x);
        return 0;
    }
    • A. 10
    • B. 0
    • C. 20
    • D. Error
    Show answer

    Answer: C. 20
    The function receives the address of x and changes x through the pointer.

  25. Q25. What does this code print?

    #include <stdio.h>
    
    void set(int v) { v = 20; }
    
    int main() {
        int x = 10;
        set(x);
        printf("%d\n", x);
        return 0;
    }
    • A. Error
    • B. 20
    • C. 0
    • D. 10
    Show answer

    Answer: D. 10
    C passes a copy of the value; the function changes only its copy.

  26. Q26. What does this code print?

    char s[] = "hello";
    printf("%zu\n", strlen(s));
    • A. Error
    • B. 5
    • C. 6
    • D. 4
    Show answer

    Answer: B. 5
    strlen counts the characters before '\0': h, e, l, l, o.

  27. Q27. What does this code print?

    char s[] = "hello";
    printf("%zu\n", sizeof(s));
    • A. 5
    • B. 6
    • C. 1
    • D. 8
    Show answer

    Answer: B. 6
    sizeof includes the terminating '\0': 5 letters + 1.

  28. Q28. What does this code print?

    int arr[] = {10, 20, 30, 40};
    int *p = arr;
    printf("%d\n", *(p + 2));
    • A. 10
    • B. 30
    • C. 20
    • D. 40
    Show answer

    Answer: B. 30
    p points to arr[0]; p + 2 points to arr[2].

  29. Q29. What does this code print?

    int n = 2;
    switch (n) {
        case 1: printf("One ");
        case 2: printf("Two ");
        case 3: printf("Three\n"); break;
        default: printf("Default\n");
    }
    • A. Three
    • B. Two
    • C. Two Three
    • D. One Two Three
    Show answer

    Answer: C. Two Three
    Without break, case 2 falls through into case 3.

  30. Q30. What does this code print?

    #include <stdio.h>
    
    int next(void) {
        static int count = 0;
        return ++count;
    }
    
    int main() {
        int a = next(), b = next(), c = next();
        printf("%d %d %d\n", a, b, c);
        return 0;
    }
    • A. 1 1 1
    • B. 3 3 3
    • C. 1 2 3
    • D. 0 1 2
    Show answer

    Answer: C. 1 2 3
    A static local keeps its value between calls.

  31. Q31. What does this code print?

    for (int i = 0; i < 3; i++) printf(i < 2 ? "%d " : "%d\n", i);
    • A. 0 1 2 3
    • B. 0 1 2
    • C. 1 2 3
    • D. Infinite loop
    Show answer

    Answer: B. 0 1 2
    The loop runs while i < 3.

  32. Q32. What does this code print?

    char ch = 'A';
    printf("%c\n", ch + 1);
    • A. A
    • B. 66
    • C. C
    • D. B
    Show answer

    Answer: D. B
    'A' + 1 is 66, which %c prints as 'B'.

  33. Q33. What does this code print?

    printf("%d\n", 5 > 3);
    • A. 0
    • B. 5
    • C. 1
    • D. Error
    Show answer

    Answer: C. 1
    In C, the comparison 5 > 3 evaluates to the int 1 (true).

  34. Q34. What does this code print?

    char a[] = "cat", b[] = "cat";
    printf(strcmp(a, b) == 0 ? "Equal\n" : "Not equal\n");
    • A. Equal
    • B. Not equal
    • C. Error
    • D. 0
    Show answer

    Answer: A. Equal
    strcmp returns 0 when the two strings have the same characters.

  35. Q35. What does this code print?

    int x = 10 % 7;
    printf("%d\n", x);
    • A. 4
    • B. 3
    • C. 1
    • D. 2
    Show answer

    Answer: B. 3
    x = 10 % 7 = 3.

  36. Q36. What does this code print?

    #include <stdio.h>
    
    void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }
    
    int main() {
        int x = 1, y = 2;
        swap(&x, &y);
        printf("%d %d\n", x, y);
        return 0;
    }
    • A. 1 1
    • B. 2 2
    • C. 1 2
    • D. 2 1
    Show answer

    Answer: D. 2 1
    swap receives addresses and exchanges the values through the pointers.

  37. Q37. What does this code print?

    #include <stdio.h>
    
    int fact(int n) { return n <= 1 ? 1 : n * fact(n - 1); }
    
    int main() {
        printf("%d\n", fact(4));
        return 0;
    }
    • A. 10
    • B. 4
    • C. 24
    • D. 120
    Show answer

    Answer: C. 24
    fact(4) = 4 × 3 × 2 × 1 = 24.

  38. Q38. What does this code print?

    #include <stdio.h>
    
    struct Student { char name[20]; int marks; };
    
    int main() {
        struct Student s = {"Kavin", 90};
        printf("%s %d\n", s.name, s.marks);
        return 0;
    }
    • A. 90 Kavin
    • B. Kavin 90
    • C. Kavin 0
    • D. Error
    Show answer

    Answer: B. Kavin 90
    Members of a struct are accessed with the dot operator.

  39. Q39. What is the return type of main() in standard C?

    • A. char
    • B. double
    • C. int
    • D. void
    Show answer

    Answer: C. int
    Return 0 for success.

  40. Q40. What is the difference between ++i and i++?

    • A. ++i increments then uses the value; i++ uses the value then increments
    • B. i++ is faster in all cases
    • C. ++i doesn't change i
    • D. They are always identical
    Show answer

    Answer: A. ++i increments then uses the value; i++ uses the value then increments
    Matters only when the expression's value is used.

  41. Q41. What does the sizeof operator return?

    • A. The size of a type or variable in bytes
    • B. The length of a string
    • C. The value of a variable
    • D. The number of elements in any pointer
    Show answer

    Answer: A. The size of a type or variable in bytes
    sizeof(int) is usually 4.

  42. Q42. What is a NULL pointer?

    • A. A pointer that points to nothing
    • B. An uninitialised pointer
    • C. A pointer to a function
    • D. A pointer to address 1
    Show answer

    Answer: A. A pointer that points to nothing
    Always check before dereferencing.

  43. Q43. What is a void pointer?

    • A. A pointer to a function returning void
    • B. A generic pointer that can hold the address of any type
    • C. A NULL pointer
    • D. A pointer that can't be used
    Show answer

    Answer: B. A generic pointer that can hold the address of any type
    malloc returns void *.

  44. Q44. What is a function pointer?

    • A. A pointer that stores the address of a function
    • B. A pointer inside a function
    • C. A function returning a pointer
    • D. A recursive function
    Show answer

    Answer: A. A pointer that stores the address of a function
    Used for callbacks, e.g. qsort's comparator.

  45. Q45. What does the extern keyword do?

    • A. Allocates memory on the heap
    • B. Makes a variable constant
    • C. Declares a variable defined in another file
    • D. Exports a function to the web
    Show answer

    Answer: C. Declares a variable defined in another file
    Used in header files for shared globals.

  46. Q46. What is the scope of a static global variable?

    • A. All files in the program
    • B. Only the function it's in
    • C. Only main()
    • D. Only the file it is defined in
    Show answer

    Answer: D. Only the file it is defined in
    static limits linkage to the current file.

  47. Q47. What does the const keyword in const int *p mean?

    • A. p itself can't change
    • B. The value pointed to can't be changed through p
    • C. Both p and the value are constant
    • D. Nothing
    Show answer

    Answer: B. The value pointed to can't be changed through p
    int *const p makes the pointer itself constant.

  48. Q48. What is the difference between malloc and calloc?

    • A. calloc zero-initialises memory; malloc doesn't
    • B. They are identical
    • C. calloc allocates on the stack
    • D. malloc zero-initialises memory
    Show answer

    Answer: A. calloc zero-initialises memory; malloc doesn't
    calloc(n, size) also takes the count separately.

  49. Q49. What does realloc do?

    • A. Frees memory
    • B. Copies a string
    • C. Changes the size of previously allocated memory
    • D. Allocates on the stack
    Show answer

    Answer: C. Changes the size of previously allocated memory
    It may move the block; use the returned pointer.

  50. Q50. What is a segmentation fault?

    • A. A missing semicolon
    • B. Accessing memory the program isn't allowed to
    • C. Running out of disk space
    • D. A syntax error
    Show answer

    Answer: B. Accessing memory the program isn't allowed to
    Often caused by NULL or dangling pointers, or out-of-bounds arrays.

  51. Q51. What is a buffer overflow?

    • A. Writing past the end of an array
    • B. Reading an empty buffer
    • C. A full stack due to recursion only
    • D. Too many files open
    Show answer

    Answer: A. Writing past the end of an array
    A common security bug; gets() is dangerous for this reason.

  52. Q52. Which function safely reads a line with a size limit?

    • A. scanf("%s")
    • B. getchar
    • C. gets
    • D. fgets
    Show answer

    Answer: D. fgets
    gets has no limit and was removed from the standard.

  53. Q53. What does the -> operator do?

    • A. Accesses a struct member through a pointer
    • B. Declares a pointer
    • C. Returns from a function
    • D. Compares two pointers
    Show answer

    Answer: A. Accesses a struct member through a pointer
    p->x equals (*p).x.

  54. Q54. What is typedef used for?

    • A. Defining a function
    • B. Creating a variable
    • C. Giving a new name to an existing type
    • D. Including a header
    Show answer

    Answer: C. Giving a new name to an existing type
    typedef struct Node Node;

  55. Q55. What is an enum in C?

    • A. A struct with methods
    • B. A set of named integer constants
    • C. A type of pointer
    • D. A string type
    Show answer

    Answer: B. A set of named integer constants
    enum Color { RED, GREEN, BLUE }; RED is 0.

  56. Q56. What is the difference between #include <file.h> and #include "file.h"?

    • A. "" is for system headers
    • B. <> searches system directories; "" searches the current directory first
    • C. <> includes source files
    • D. They are identical
    Show answer

    Answer: B. <> searches system directories; "" searches the current directory first
    Use quotes for your own headers.

  57. Q57. What is a macro?

    • A. A large function
    • B. A library
    • C. A preprocessor text substitution defined with #define
    • D. A type of loop
    Show answer

    Answer: C. A preprocessor text substitution defined with #define
    Macros have no type checking; inline functions are safer.

  58. Q58. What is the output stream for error messages in C?

    • A. stderr
    • B. stdlog
    • C. stdout
    • D. stdin
    Show answer

    Answer: A. stderr
    fprintf(stderr, "...").

  59. Q59. What does the break statement do in a loop?

    • A. Restarts the loop
    • B. Exits the loop immediately
    • C. Ends the program
    • D. Skips to the next iteration
    Show answer

    Answer: B. Exits the loop immediately
    continue skips to the next iteration.

  60. Q60. What is an infinite loop?

    • A. A loop with break
    • B. A loop with a large array
    • C. A recursive function
    • D. A loop whose condition never becomes false
    Show answer

    Answer: D. A loop whose condition never becomes false
    for (;;) or while (1).

  61. Q61. What is the purpose of the volatile keyword in C?

    • A. Makes a variable global
    • B. Tells the compiler a variable may change outside the program's control
    • C. Allocates memory dynamically
    • D. Makes a variable constant
    Show answer

    Answer: B. Tells the compiler a variable may change outside the program's control
    Used for hardware registers and signal handlers.

  62. Q62. What is the range of an unsigned char?

    • A. 0 to 255
    • B. 0 to 65535
    • C. 0 to 127
    • D. -128 to 127
    Show answer

    Answer: A. 0 to 255
    8 bits, no sign.

  63. Q63. What does the bitwise operator & do on 6 & 3?

    • A. 7
    • B. 5
    • C. 1
    • D. 2
    Show answer

    Answer: D. 2
    110 & 011 = 010.

  64. Q64. What does 1 << 3 evaluate to?

    • A. 6
    • B. 8
    • C. 4
    • D. 3
    Show answer

    Answer: B. 8
    Shifting left by 3 multiplies by 2³.

  65. Q65. What does the ternary operator a > b ? a : b give?

    • A. The larger of a and b
    • B. true or false only
    • C. a + b
    • D. The smaller of a and b
    Show answer

    Answer: A. The larger of a and b
    condition ? valueIfTrue : valueIfFalse.

  66. Q66. What is recursion's main risk in C?

    • A. Stack overflow from too many nested calls
    • B. Compile errors
    • C. Memory leaks on the heap
    • D. Integer overflow always
    Show answer

    Answer: A. Stack overflow from too many nested calls
    Every call uses stack space.

  67. Q67. What does the storage class 'register' suggest?

    • A. Keep the variable in a CPU register if possible
    • B. Store it on the heap
    • C. Make it global
    • D. Make it constant
    Show answer

    Answer: A. Keep the variable in a CPU register if possible
    Modern compilers mostly ignore it.

  68. Q68. What is the difference between a declaration and a definition?

    • A. A definition only names the type
    • B. A declaration announces a name and type; a definition also allocates storage or provides the body
    • C. They are the same
    • D. Declarations allocate memory
    Show answer

    Answer: B. A declaration announces a name and type; a definition also allocates storage or provides the body
    extern int x; declares; int x = 5; defines.

  69. Q69. What does this code print?

    printf("%d\n", 6 & 3);
    • A. 7
    • B. 2
    • C. 5
    • D. 1
    Show answer

    Answer: B. 2
    6 & 3: binary 110 & 011 = 010.

  70. Q70. What does this code print?

    printf("%d\n", 6 | 3);
    • A. 2
    • B. 7
    • C. 5
    • D. 4
    Show answer

    Answer: B. 7
    6 | 3: 110 | 011 = 111.

  71. Q71. What does this code print?

    printf("%d\n", 6 ^ 3);
    • A. 2
    • B. 7
    • C. 1
    • D. 5
    Show answer

    Answer: D. 5
    6 ^ 3: 110 ^ 011 = 101.

  72. Q72. What does this code print?

    printf("%d\n", 1 << 3);
    • A. 6
    • B. 16
    • C. 8
    • D. 3
    Show answer

    Answer: C. 8
    1 << 3 shifts 1 left three times.

  73. Q73. What does this code print?

    printf("%d\n", 16 >> 2);
    • A. 16
    • B. 4
    • C. 8
    • D. 2
    Show answer

    Answer: B. 4
    16 >> 2 divides by 4.

  74. Q74. What does this code print?

    printf("%d\n", 7 % 3);
    • A. 0
    • B. 1
    • C. 2
    • D. -1
    Show answer

    Answer: B. 1
    7 divided by 3 leaves a remainder of 1.

  75. Q75. What does this code print?

    printf("%d\n", -7 % 2);
    • A. 3
    • B. -3
    • C. -1
    • D. 1
    Show answer

    Answer: C. -1
    In C the remainder takes the sign of the dividend: -7 % 2 is -1.

  76. Q76. What does this code print?

    printf("%d\n", -7 / 2);
    • A. -3
    • B. 3
    • C. -4
    • D. -3.5
    Show answer

    Answer: A. -3
    Integer division in C truncates towards zero.

  77. Q77. What does this code print?

    int a[] = {10, 20, 30};
    for (int *p = a; p < a + 3; p++) printf(p < a + 2 ? "%d " : "%d\n", *p);
    • A. 10 10 10
    • B. Error
    • C. 30 20 10
    • D. 10 20 30
    Show answer

    Answer: D. 10 20 30
    The loop walks the array with a pointer.

  78. Q78. What does this code print?

    char *s = "Hello";
    printf("%c\n", *s);
    • A. Hello
    • B. e
    • C. 72
    • D. H
    Show answer

    Answer: D. H
    *s is the first character of the string.

  79. Q79. What does this code print?

    char *s = "Hello";
    printf("%s\n", s + 2);
    • A. Hello
    • B. l
    • C. llo
    • D. lo
    Show answer

    Answer: C. llo
    s + 2 points at the third character; %s prints from there.

  80. Q80. What does this code print?

    printf("%d\n", 'A');
    • A. 97
    • B. A
    • C. a
    • D. 65
    Show answer

    Answer: D. 65
    %d prints the character's ASCII code.

  81. Q81. What does this code print?

    int x = (1, 2, 3);
    printf("%d\n", x);
    • A. Error
    • B. 3
    • C. 2
    • D. 4
    Show answer

    Answer: B. 3
    The comma operator evaluates both and yields the last value.

  82. Q82. What does this code print?

    #include <stdio.h>
    
    int g;
    
    int main() {
        printf("%d\n", g);
        return 0;
    }
    • A. Error
    • B. garbage
    • C. 1
    • D. 0
    Show answer

    Answer: D. 0
    Static and global variables start at 0.

  83. Q83. What does this code print?

    int x = 5;
    int a = x++;
    int b = ++x;
    printf("%d\n", a + b);
    • A. 12
    • B. 11
    • C. 13
    • D. 10
    Show answer

    Answer: A. 12
    x++ uses 5 then x becomes 6; ++x makes it 7: 5 + 7 = 12.

  84. Q84. What does this code print?

    printf("%d\n", !0);
    • A. Error
    • B. 0
    • C. 5
    • D. 1
    Show answer

    Answer: D. 1
    !0 is 1.

  85. Q85. What does this code print?

    printf("%d\n", !5);
    • A. 1
    • B. 0
    • C. -5
    • D. 5
    Show answer

    Answer: B. 0
    !5 is 0 because 5 is true.

  86. Q86. What does this code print?

    printf("%d\n", 10 / 3 * 3);
    • A. 10
    • B. 9
    • C. 3
    • D. Error
    Show answer

    Answer: B. 9
    Integer division happens first: 10 / 3 = 3, then 3 * 3 = 9.

  87. Q87. What does this code print?

    #include <stdio.h>
    #define SQUARE(x) x * x
    
    int main() {
        printf("%d\n", SQUARE(3 + 1));
        return 0;
    }
    • A. 9
    • B. 16
    • C. Error
    • D. 7
    Show answer

    Answer: D. 7
    The macro has no brackets: SQUARE(3 + 1) becomes 3 + 1 * 3 + 1 = 7. A classic macro bug!

  88. Q88. What does this code print?

    #include <stdio.h>
    #define SQUARE(x) ((x) * (x))
    
    int main() {
        printf("%d\n", SQUARE(3 + 1));
        return 0;
    }
    • A. 9
    • B. 16
    • C. 7
    • D. Error
    Show answer

    Answer: B. 16
    With brackets around x the macro expands safely: (3 + 1) * (3 + 1).

  89. Q89. What does this code print?

    #include <stdio.h>
    
    void show(int n) {
        if (n == 0) return;
        show(n - 1);
        printf(n == 3 ? "%d\n" : "%d ", n);
    }
    
    int main() {
        show(3);
        return 0;
    }
    • A. 1 1 1
    • B. 3 2 1
    • C. 1 2 3
    • D. Error
    Show answer

    Answer: C. 1 2 3
    Each recursive call prints after returning, so the deepest call (1) prints first.

  90. Q90. What does this code print?

    #include <stdio.h>
    
    void show(int n) {
        if (n == 0) return;
        printf(n == 1 ? "%d\n" : "%d ", n);
        show(n - 1);
    }
    
    int main() {
        show(3);
        return 0;
    }
    • A. 1 2 3
    • B. 3 2 1
    • C. 3 3 3
    • D. Error
    Show answer

    Answer: B. 3 2 1
    Printing before the recursive call shows 3 first.

  91. Q91. What does this code print?

    int a[] = {5, 8, 2, 9, 0, 7};
    int n = 0;
    while (a[n] != 0) n++;
    printf("%d\n", n);
    • A. 5
    • B. 3
    • C. Error
    • D. 4
    Show answer

    Answer: D. 4
    The loop counts elements until it reaches the 0: 5, 8, 2 and 9.

  92. Q92. What does this code print?

    int a = 9, b = 8;
    printf("%d\n", a > b ? a : b);
    • A. 1
    • B. 8
    • C. 10
    • D. 9
    Show answer

    Answer: D. 9
    The ternary picks the larger value.

  93. Q93. What does this code print?

    int n = 7;
    printf((n & 1) ? "Odd\n" : "Even\n");
    • A. 1
    • B. Odd
    • C. Even
    • D. Error
    Show answer

    Answer: B. Odd
    7 & 1 is 1, so the number is odd.

  94. Q94. What does this code print?

    int n = 11, count = 0;
    while (n) { count += n & 1; n >>= 1; }
    printf("%d\n", count);
    • A. 2
    • B. 3
    • C. 4
    • D. 8
    Show answer

    Answer: B. 3
    Counting set bits of 11 (binary 1011).

  95. Q95. What does this code print?

    char s[] = "abc";
    int i = 0, j = strlen(s) - 1;
    while (i < j) { char t = s[i]; s[i] = s[j]; s[j] = t; i++; j--; }
    printf("%s\n", s);
    • A. a
    • B. abc
    • C. Error
    • D. cba
    Show answer

    Answer: D. cba
    The two-pointer swap reverses the string in place.

Practised these? Now prove it.

Take a timed mock test with new questions every attempt, earn a verified certificate at 70%+, and get noticed by employers.

Start a mock test