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

CSE MCQs :: C-MCQs

  1. What is the output of this C code?

    int
    x = 0;
    void main()
    {
    int *const ptr = &x;
    printf("%p\n", ptr);
    ptr++;
    printf("%p\n ", ptr);
    }
  2. A.
    0  1
    B.
    Compile time error
    C.
    0xbfd605e8   0xbfd605ec
    D.
    0xbfd605e8   0xbfd605e8

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What is the output of this C code?

    void main()
    {
    int x = 0;
    int *ptr = &x;
    printf("%p\n", ptr);
    ptr++;
    printf("%p\n ", ptr);
    }
  4. A.
    0xbfd605e8   0xbfd605ec
    B.
    0xbfd605e8   0cbfd60520
    C.
    0xbfd605e8   0xbfd605e9
    D.
    Run time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What is the output of this C code?

    void main()
    {
    int x = 0;
    int *ptr = &5;
    printf("%p\n", ptr);
    }
  6. A.
    5
    B.
    Address of 5
    C.
    Nothing
    D.
    Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What is the output of this C code?

    void foo(int*);
    int main()
    {
    int i = 10;
    foo((&i)++);
    }
    void foo(int *p)
    {
    printf("%d\n", *p);
    }
  8. A.
    10
    B.
    Some garbage value
    C.
    Compile time error
    D.
    Segmentation fault/code crash

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What is the output of this C code?

    void foo(int*);
    int main()
    {
    int i = 10, *p = &i;
    foo(p++);
    }
    void foo(int *p)
    {
    printf("%d\n", *p);
    }
  10. A.
    10
    B.
    Some garbage value
    C.
    Compile time error
    D.
    Segmentation fault

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What is the output of this C code?

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

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What is the output of this C code?

    int main()
    {
    int i = 97, *p = &i;
    foo(&i);
    printf("%d ", *p);
    }
    void foo(int *p)
    {
    int j = 2;
    p = &j;
    printf("%d ", *p);
    }
  14. A.
    2   97
    B.
    2   2
    C.
    Compile time error
    D.
    Segmentation fault/code crash

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What is the output of this C code?

    int main()
    {
    int i = 97, *p = &i;
    foo(&p);
    printf("%d ", *p);
    return 0;
    }
    void foo(int **p)
    {
    int j = 2;
    *p = &j;
    printf("%d ", **p);
    }
  16. A.
    2   2
    B.
    2   97
    C.
    Undefined behaviour
    D.
    Segmentation fault/code crash

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. What is the output of this C code?

    int main()
    {
    int i = 11;
    int *p = &i;
    foo(&p);
    printf("%d ", *p);
    }
    void foo(int *const *p)
    {
    int j = 10;
    *p = &j;
    printf("%d ", **p);
    }
  18. A.
    Compile time error
    B.
    10   10
    C.
    Undefined behaviour
    D.
    10   11

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. What is the output of this C code?

    int
    main()
    {
    int i = 10;
    int *p = &i;
    foo(&p);
    printf("%d ", *p);
    printf("%d ", *p);
    }
    void foo(int **const p)
    {
    int j = 11;
    *p = &j;
    printf("%d ", **p);
    }
  20. A.
    11   11   11
    B.
    11  11 Undefined-value
    C.
    Compile time error
    D.
    Segmentation fault/code-crash

    View Answer

    Workspace

    Discuss Discuss in Forum