Pointers


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Compilation Error

    main.c: In function ‘main’:
    main.c:6:29: warning: dereferencing ‘void *’ pointer
    printf("%d\n", (int)*ptr);
    ^~~~
    main.c:6:24: error: invalid use of void expression
    printf("%d\n", (int)*ptr);


  1. What will be the output of the following C code?
     #include <stdio.h>
    int main()
    {
    int num = 110;
    void *ptr = #
    printf("%f\n", *(float*)ptr);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    0.000000



  1. What will be the output of the following C code?
    #include <stdio.h>
    int *fun();
    int main()
    {
    int *ptr = fun();
    printf("%d\n", *ptr);
    }
    int *fun()
    {
    int *p = (int*)malloc(sizeof(int));
    *p = 11;
    return p;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    11


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    25, 25



  1. Which is an indirection operator among the following?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    *