Home / CSE MCQs / C-MCQs :: Declarations - C

CSE MCQs :: C-MCQs

  1. What is the output of this C code?

    void foo(const int *);
    int main()
    {
    const int i = 10;
    printf("%d ", i);
    foo(&i);
    printf("%d", i);
    }
    void foo(const int *i)
    {
    *i = 20;
    }
  2. A.
    Compile time error
    B.
    10    20
    C.
    Undefined value
    D.
    10

  3. Comment on the output of this C code?

    int main()
    {
    const int i = 10;
    int *ptr = &i;
    *ptr = 20;
    printf("%d\n", i);
    return 0;
    }
  4. A.
    Compile time error
    B.
    Compile time warning and printf displays 20
    C.
    Undefined behaviour
    D.
    10

  5. Does this compile without error?

    int main()
    {
    for (int k = 0; k < 10; k++);
    return 0;
    }
  6. A.
    Yes
    B.
    No
    C.
    Depends on the C standard implemented by compilers
    D.
    None of the mentioned

  7. Does this compile without error?

    int main()
    {
    int k;
    {
    int k;
    for (k = 0; k < 10; k++);
    }
    }
  8. A.
    Yes
    B.
    No
    C.
    Depends on the compiler
    D.
    Depends on the C standard implemented by compilers

  9. Which of the following declaration is not supported by C?
  10. A.
    String str;
    B.
    char *str;
    C.
    float str = 3e2;
    D.
    Both (a) and (c)

  11. Which of the following format identifier can never be used for the variable var?

    int main()
    {
    char *var = "Advanced Training in C by AllIndiaExams.com";
    }
  12. A.
    %f
    B.
    %d
    C.
    %c
    D.
    %s

  13. Which keyword is used to prevent any changes in the variable within a C program?
  14. A.
    immutable
    B.
    mutable
    C.
    const
    D.
    volatile

  15. Which of the following is not a pointer declaration?
  16. A.
    char a[10];
    B.
    char a[] = {'1', '2', '3', '4'};
    C.
    char *str;
    D.
    char a;

  17. What is the output of this C code?

    void main()
    {
    int k = 4;
    float k = 4;
    printf("%d", k)
    }
  18. A.
    Compile time error
    B.
    4
    C.
    4.0000000
    D.
    4.4

  19. Which is false ?
  20. A.
    A variable defined once can be defined again with different scope
    B.
    A single variable cannot be defined with two different types in the same scope
    C.
    A variable must be declared and defined at the same time
    D.
    A variable refers to a location in memory