Create New Post

C MCQs - 10

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

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

    a) 0 2 4 6
    b) 1 3 5
    c) 0 1 2 3 4
    d) 1 2 3 4 5

    Answer: c) 0 1 2 3 4

  2. In C, which of the following functions is used to close a file?

    a) close()
    b) fclose()
    c) endfile()
    d) fileclose()

    Answer: b) fclose()

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

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

    a) 5, 5, 9
    b) 5, 10, 9
    c) 10, 5, 9
    d) 10, 10, 9

    Answer: b) 5, 10, 9

  4. Which of the following functions is used to read a single character from the standard input in C?

    a) getchar()
    b) gets()
    c) scanf()
    d) read()

    Answer: a) getchar()

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

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

    a) 5.000000
    b) 5
    c) Compiler error
    d) Undefined behavior

    Answer: a) 5.000000

  6. In C, which of the following operators is used to access the address of a variable?

    a) &
    b) *
    c) ->
    d) .

    Answer: a) &

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

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

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

    Answer: b) 5, 10, 11

  8. What does the fgets() function in C do?

    a) Reads a line from a file
    b) Reads a character from a file
    c) Reads a line from the console
    d) Reads a character from the console

    Answer: a) Reads a line from a file

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

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

    a) 5 4 3 2 1 0
    b) 5 4 3 2 1
    c) 4 3 2 1 0
    d) 4 3 2 1

    Answer: a) 5 4 3 2 1 0

  10. In C, which function is used to convert a string to a floating-point number?

a) atof()   

b) atoi()  
c) strtod()  
d) float_convert()  

**Answer: a) atof()**
 

 

Comments

Leave a Reply

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

73168