Pointers


  1. What will be the output of the following C code?
    #include <stdio.h>
    void fun(int*);
    int main()
    {
    int num = 10;
    fun((&num)++);
    }
    void fun(int *ptr)
    {
    printf("%d\n", *ptr);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Compilation Error

    main.c: In function ‘main’:
    main.c:6:19: error: lvalue required as increment operand
    fun((&num)++);


  1. What will be the output of the following C code?
    #include <stdio.h>
    void main()
    {
    int var = 101;
    int *p = &var;
    printf("%d\n", *p);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    101



  1. What will be the output of the following C code?
    #include <stdio.h>
    void main()
    {
    int var = 10;
    int *p = &15;
    printf("%p\n", p);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Compilation Error

    main.c: In function ‘main’:
    main.c:5:18: error: lvalue required as unary ‘&’ operand
    int *p = &15;


  1. What will be the output of the following C code?
    #include <stdio.h>
    void main()
    {
    int n = 0;
    int *p = &n;
    printf("%p\n", p);
    p++;
    printf("%p\n ", p);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    0x7ffc391e1404
    0x7ffc391e1408



  1. What will be the output of the following C code?
    #include <stdio.h>
    int n = 0;
    void main()
    {
    int *const p = &n;
    printf("%p\n", p);
    p++;
    printf("%p\n ", p);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    main.c: In function ‘main’:
    main.c:7:10: error: increment of read-only variable ‘p’
    p++;