Create New Post

C MCQs - 4

  1. What does the fprintf() function do in C?

    a) Reads formatted data from a file
    b) Writes formatted data to a file
    c) Reads formatted data from the console
    d) Writes formatted data to the console

    Answer: b) Writes formatted data to a file

  2. In C, what does the extern keyword signify when used with a variable declaration?

    a) The variable is initialized with an external value
    b) The variable is declared without any storage allocation
    c) The variable is declared in another file and is available for use in the current file
    d) The variable is of external linkage

    Answer: c) The variable is declared in another file and is available for use in the current file

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

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

    a) 5, 5
    b) 5, 6
    c) 6, 6
    d) Compiler error

    Answer: b) 5, 6

  4. Which function is used to copy a block of memory in C?

    a) memcpy()
    b) memmove()
    c) strcpy()
    d) strcat()

    Answer: a) memcpy()

  5. What is the output of the following code?

    #include <stdio.h>
    int main() {
        int arr[] = {1, 2, 3, 4, 5};
        int *ptr = arr;
        printf("%d\n", *ptr++);
        printf("%d\n", *ptr);
        return 0;
    }
     

    a) 1, 2
    b) 1, 1
    c) 2, 2
    d) 2, 1

    Answer: a) 1, 2

  6. Which of the following is NOT a valid format specifier for printing a double in C?

    a) %f
    b) %lf
    c) %d
    d) %e

    Answer: c) %d

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

    #include <stdio.h>
    int main() {
        char str[6] = "Hello";
        printf("%s\n", str);
        return 0;
    }
     

    a) Hello
    b) Hello!
    c) Compiler error
    d) Undefined behavior

    Answer: a) Hello

  8. Which of the following statements is true about the do-while loop in C?

    a) The loop condition is checked before executing the loop body
    b) The loop condition is checked after executing the loop body
    c) The loop executes only if the condition is true
    d) The loop always executes at least once

    Answer: d) The loop always executes at least once

  9. What does the putc() function do in C?

    a) Reads a character from a file
    b) Writes a character to a file
    c) Reads a character from the console
    d) Writes a character to the console

    Answer: b) Writes a character to a file

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

    #include <stdio.h>
    int main() {
        int x = 10;
        int *ptr = &x;
        printf("%p\n", ptr);
        return 0;
    }
     

    a) Address of x
    b) Value of x
    c) Address of ptr
    d) Compiler error

    Answer: a) Address of x

Comments

Leave a Reply

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

29879