-
What will be the output of the following C code?
#include <stdio.h>
int *fun();
void main()
{
int *ptr = fun();
printf("Welcome ");
printf("%d", ptr[0]);
}
int *fun()
{
int n[5] = {15, 18, 10};
return n;
}
-
- Compilation Error
- Welcome
- 15 18 10
- Segmentation fault
- None of these
Correct Option: D
Segmentation fault
main.c: In function ‘fun’:
main.c:12:16: warning: function returns address of local variable [-Wreturn-local-addr]
return n;
^
$main
timeout: the monitored command dumped core
sh: line 1: 179205 Segmentation fault timeout 10s main