Functions
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int n = fun();
printf("%d", n);
}
void fun()
{
printf("Welcome ");
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Welcome 8
- What will be the output of the following C code?
#include <stdio.h>
int *fun()
{
int *ptr1 = 10;
return ptr1;
}
void main()
{
int *ptr2 = fun();
printf("%d", ptr2);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
10
- 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;
}
-
View Hint View Answer Discuss in Forum
NA
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
- What will be the output of the following C code?
#include <stdio.h>
int *fun();
void main()
{
int n = A();
printf("%d", n);
}
int *fun()
{
int num[5] = {51, 18, 25};
return num;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Compilation Error
main.c: In function ‘main’:
main.c:5:17: warning: implicit declaration of function ‘A’ [-Wimplicit-function-declaration]
int n = A();
^
main.c: In function ‘fun’:
main.c:11:16: warning: function returns address of local variable [-Wreturn-local-addr]
return num;
^~~
/tmp/ccNdhoL1.o: In function `main':
main.c:(.text+0xe): undefined reference to `A'
collect2: error: ld returned 1 exit status
- What will be the output of the following C code?
#include <stdio.h>
enum color{Red, Yellow, Green};
enum color fun();
int main()
{
enum color n = fun();
printf("%d\n", n);
}
int fun()
{
return Red;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Compilation Error
main.c:9:10: error: conflicting types for ‘fun’
int fun()
^~~
main.c:3:16: note: previous declaration of ‘fun’ was here
enum color fun();