Create New Post

C MCQs - 6

  1. Which of the following is true regarding the sizeof operator in C?

    a) It is a preprocessor directive
    b) It returns the size of a variable in bits
    c) It can be used with any data type including user-defined types
    d) It can be used to determine the size of dynamic memory allocations

    Answer: c) It can be used with any data type including user-defined types

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

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

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

    Answer: d) Undefined behavior

  3. In C, what is the purpose of the continue statement?

    a) To terminate the program
    b) To exit the loop and transfer control to the loop's condition check
    c) To skip the remaining code in the loop and continue with the next iteration
    d) To jump to a labeled statement

    Answer: c) To skip the remaining code in the loop and continue with the next iteration

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

    a) strcomp()
    b) strcmp()
    c) strcompare()
    d) compare()

    Answer: b) strcmp()

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

    #include <stdio.h>
    int main() {
        int x = 5, y = 10;
        if (x = y)
            printf("x is equal to y\n");
        else
            printf("x is not equal to y\n");
        return 0;
    }
    

    a) x is equal to y
    b) x is not equal to y
    c) Compiler error
    d) No output

    Answer: a) x is equal to y

  6. Which header file is required to use the pow() function in C?

    a) <stdio.h>
    b) <stdlib.h>
    c) <math.h>
    d) <ctype.h>

    Answer: c) <math.h>

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

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

    a) x = 5, y = 10
    b) x = 10, y = 5
    c) x = 0, y = 0
    d) Compiler error

    Answer: b) x = 10, y = 5

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

    a) Checks if a character is a digit
    b) Converts a character to its lowercase equivalent
    c) Converts a character to its uppercase equivalent
    d) Checks if a character is a whitespace character

    Answer: a) Checks if a character is a digit

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

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

    a) 5, 7
    b) 5, 6
    c) 6, 6
    d) 6, 7

    Answer: b) 5, 6

  10. In C, what is the purpose of the goto statement?

    a) To exit a loop
    b) To transfer control to a labeled statement
    c) To skip the remaining code in a loop and continue with the next iteration
    d) To terminate the program

    Answer: b) To transfer control to a labeled statement

Comments

Leave a Reply

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

21279