Home / CSE MCQs / C-MCQs :: Pointers - C

CSE MCQs :: C-MCQs

  1. What is the output of this C code?

    int main()
    {
    char *p = NULL;
    char *q = 0;
    if (p)
    printf(" p ");
    else
    printf("nullp");
    if (q)
    printf("q\n");
    else
    printf(" nullq\n");
    }
  2. A.
    nullp  nullq
    B.
    Depends on the compiler
    C.
    x nullq where x can be p or nullp depending on the value of NULL
    D.
    p   q

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What is the output of this C code?

    int main()
    {
    int i = 10;
    void *p = &i;
    printf("%d\n", (int)*p);
    return 0;
    }
  4. A.
    Compile time error
    B.
    Segmentation fault/runtime crash
    C.
    10
    D.
    Undefined behaviour

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What is the output of this C code?

    int main()
    {
    int i = 10;
    void *p = &i;
    printf("%f\n", *(float*)p);
    return 0;
    }
  6. A.
    Compile time error
    B.
    Undefined behaviour
    C.
    10
    D.
    0.000000

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What is the output of this C code?

    int *f();
    int main()
    {
    int *p = f();
    printf("%d\n", *p);
    }
    int *f()
    {
    int *j = (int*)malloc(sizeof(int));
    *j = 10;
    return j;
    }
  8. A.
    10
    B.
    Compile time error
    C.
    Segmentation fault/runtime crash since pointer to local variable is returned
    D.
    Undefined behaviour

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What is the output of this C code?

    int *f();
    int main()
    {
    int *p = f();
    printf("%d\n", *p);
    }
    int *f()
    {
    int j = 10;
    return &j;
    }
  10. A.
    10
    B.
    Compile time error
    C.
    Segmentation fault/runtime crash
    D.
    Undefined behaviour

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What is the output of this C code?

    int
    main()
    {
    int *ptr, a = 10;
    ptr = &a;
    *ptr += 1;
    printf("%d,%d/n", *ptr, a);
    }
  12. A.
    10,10
    B.
    10,11
    C.
    11,10
    D.
    11,11

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. Comment on the following?
    const int *ptr;
  14. A.
    You cannot change the value pointed by ptr
    B.
    You cannot change the pointer ptr itself
    C.
    Both (a) and (b)
    D.
    You can change the pointer as well as the value pointed by it

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. Which is an indirection operator among the following?
  16. A.
    &
    B.
    *
    C.
    ->
    D.
    .

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0)?
  18. A.
    int *ptr = &a;
    B.
    int *ptr = &a "“ &a;
    C.
    int *ptr = a "“ a;
    D.
    All of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. What is the output of this C code?

    int x = 0;
    void main()
    {
    int *ptr = &x;
    printf("%p\n", ptr);
    x++;
    printf("%p\n ", ptr);
    }
  20. A.
    Same address
    B.
    Different address
    C.
    Compile time error
    D.
    Varies

    View Answer

    Workspace

    Discuss Discuss in Forum