Create New Post

C MCQs - 3

  1. What will be the output of the following code?

    #include <stdio.h>
    int main() {
        int x = 5;
        int y = 10;
        int z = (x > y) ? x : y;
        printf("%d\n", z);
        return 0;
    }
     

    a) 5
    b) 10
    c) 15
    d) Compiler error

    Answer: b) 10

  2. Which keyword is used to terminate the execution of a function in C?

    a) stop
    b) end
    c) return
    d) terminate

    Answer: c) return

  3. What is the output of the following code snippet?

    int x = 5, y = 10;
    printf("%d\n", x++);
    printf("%d\n", ++y);
     

    a) 5, 11
    b) 6, 11
    c) 6, 10
    d) 5, 10

    Answer: d) 5, 10

  4. Which function is used to concatenate two strings in C?

    a) strcat()
    b) concat()
    c) append()
    d) join()

    Answer: a) strcat()

  5. What will be the output of the following code snippet?

    #include <stdio.h>
    int main() {
        int i;
        for (i = 0; i < 5; i++) {
            if (i == 3)
                break;
            printf("%d ", i);
        }
        return 0;
    }
     

    a) 0 1 2
    b) 0 1 2 3
    c) 0 1 2 3 4
    d) Compiler error

    Answer: a) 0 1 2

  6. Which escape sequence is used to print a newline character in C?

    a) \n
    b) \r
    c) \t
    d) \b

    Answer: a) \n

  7. What does the calloc() function do in C?

    a) Allocates memory on the stack
    b) Allocates memory on the heap
    c) Frees memory
    d) Resizes memory

    Answer: b) Allocates memory on the heap

  8. Which operator is used to find the remainder of division in C?

    a) %
    b) /
    c) *
    d) &

    Answer: a) %

  9. What is the output of the following code snippet?

    #include <stdio.h>
    int main() {
        int i;
        for (i = 0; i < 5; i++) {
            if (i == 3)
                continue;
            printf("%d ", i);
        }
        return 0;
    }
     

    a) 0 1 2
    b) 0 1 2 3
    c) 0 1 2 4
    d) Compiler error

    Answer: c) 0 1 2 4

  10. Which function is used to dynamically deallocate memory in C?

    a) free()
    b) dealloc()
    c) delete()
    d) release()

    Answer: a) free()

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

68683