Create New Post

C MCQs - 1

  1. What does the sizeof operator return in C?

    a) Size of a variable in bytes
    b) Size of a datatype in bytes
    c) Size of a pointer in bytes
    d) Size of the code segment in bytes

    Answer: b) Size of a datatype in bytes

  2. Which keyword is used to define a constant in C?

    a) const
    b) constant
    c) define
    d) var

    Answer: a) const

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

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

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

    Answer: a) 15

  4. Which one of the following is the correct way to declare a pointer in C?

    a) int ptr;
    b) int ptr
    ;
    c) int ptr;
    d) pointer int;

    *Answer: a) int ptr;

  5. What is the value of x after the following code is executed?

    int x = 10;
    int *ptr = &x;
    *ptr = 20;
    

    a) 10
    b) 20
    c) Undefined
    d) Compiler error

    Answer: b) 20

  6. What does the strcmp() function do in C?

    a) Copies one string to another
    b) Compares two strings
    c) Concatenates two strings
    d) Searches for a substring in a string

    Answer: b) Compares two strings

  7. What does the malloc() 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 header file is required for using dynamic memory allocation functions in C?

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

    Answer: b) <stdlib.h>

  9. What is the purpose of the break statement in C?

    a) To exit a loop
    b) To skip the current iteration of a loop
    c) To branch unconditionally
    d) To terminate the program

    Answer: a) To exit a loop

  10. Which one of the following is a valid way to declare a multi-dimensional array in C?

    a) int arr[5][];
    b) int arr[][];
    c) int arr[][5];
    d) int arr[][];

    Answer: c) int arr[][5];

Comments

Leave a Reply

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

77700