Home » C Programming » Pointers » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    void function(int);
    void (*fun)(void) = function;
    int main(int argc, char *argv[])
    {
    fun(20);
    return 0;
    }
    void function(int k)
    {
    printf("%d\n", k);
    }
    1. Compilation Error
    2. Garbage value
    3. 20
    4. Runtime Error
    5. None of these
Correct Option: A

Compilation Error

main.c:3:25: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
void (*fun)(void) = function;
^~~~~~~~
main.c: In function ‘main’:
main.c:6:9: error: too many arguments to function ‘fun’
fun(20);



Your comments will be displayed only after manual approval.