Create New Post

C MCQs - 8

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

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

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

    Answer: a) 0 1 2

  2. In C, which escape sequence is used to represent a backslash character?

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

    Answer: d) \

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

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

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

    Answer: a) 10, 11

  4. Which function is used to find the smallest integer not less than x in C?

    a) ceil()
    b) floor()
    c) round()
    d) trunc()

    Answer: a) ceil()

  5. What does the isalpha() function in C do?

    a) Checks if a character is alphabetic
    b) Checks if a character is a digit
    c) Checks if a character is a whitespace character
    d) Checks if a character is a punctuation character

    Answer: a) Checks if a character is alphabetic

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

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

    a) 3
    b) 3.3333
    c) 3.0
    d) Compiler error

    Answer: a) 3

  7. Which of the following is NOT a valid way to declare and initialize a string in C?

    a) char str[] = "Hello";
    b) char str[6] = "Hello";
    c) char str[] = {'H', 'e', 'l', 'l', 'o', '\0'};
    d) char str[5] = "Hello";

    Answer: d) char str[5] = "Hello";

  8. What is the output of the following code?

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

    Answer: b) 10

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

    a) Copies one string to another
    b) Compares two strings
    c) Concatenates two strings
    d) Copies a specified number of characters from one string to another

    Answer: d) Copies a specified number of characters from one string to another

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

     #include <stdio.h>
    int main() {
        int x = 10;
        printf("%p\n", &x);
        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 *

76754