-
What will be the output of the following C code?
#include <stdio.h>
int (*(a()))[2];
typedef int (*(*p)())[2] ptrfun;
int main()
{
ptrfun p1;
p1 = a;
p1();
return 0;
}
int (*(a()))[2]
{
int (*array)[2] = malloc(sizeof*array);
return &array;
}
-
- Nothing
- Undefined behaviour
- Compilation Error
- Garbage value
- None of these
Correct Option: C
Compilation Error
main.c:3:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ptrfun’
typedef int (*(*p)())[2] ptrfun;
^~~~~~
main.c: In function ‘main’:
main.c:6:9: error: unknown type name ‘ptrfun’
ptrfun p1;
^~~~~~
main.c:7:12: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
p1 = a;
^
main.c:8:9: error: called object ‘p1’ is not a function or function pointer
p1();
^~
main.c:6:16: note: declared here
ptrfun p1;
^~
main.c: In function ‘a’:
main.c:13:27: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
int (*array)[2] = malloc(sizeof*array);
^~~~~~
main.c:13:27: warning: incompatible implicit declaration of built-in function ‘malloc’
main.c:13:27: note: include ‘’ or provide a declaration of ‘malloc’
main.c:14:16: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
return &array;
^~~~~~
main.c:14:16: warning: function returns address of local variable [-Wreturn-local-addr]