Home » C Programming » Pointers » Question
  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. Compilation Error
    2. Garbage value
    3. 12
    4. Nothing
    5. None of these
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);



Your comments will be displayed only after manual approval.