C- Functions Question and Answer
C- Functions Question and Answer
111. Every function internally creates
- Array of frames
- Linked list of frames
- Tree of frames
- None of these
112. Find the output
void main ( )
{
void show (int);
int n=1000;
show (n);
}
void show (int x)
{
if (x !=0)
{
show (x/16);
putchar("0123456789ABCDEF" [x%16]);
}
else
return 0;
}
void main ( )
{
void show (int);
int n=1000;
show (n);
}
void show (int x)
{
if (x !=0)
{
show (x/16);
putchar("0123456789ABCDEF" [x%16]);
}
else
return 0;
}
- 2E8
- 2D7
- 3E8
- None of these
113. Find the correct output
void main( )
{
int n=5;
printf("%d",f(n));
}
int f(int n)
{
if (n>0)
return (n+f(n-2));
else
return 0;
}
void main( )
{
int n=5;
printf("%d",f(n));
}
int f(int n)
{
if (n>0)
return (n+f(n-2));
else
return 0;
}
- 9
- 15
- 8
- None of these
114. Find the output
void main ( )
{
int a [ ]={1, 2, 3, 4};
int i, s=0;
for (i=0; a[i];i++)
s+=add (a[i]);
printf("%d",s);
}
int add (int a)
{
static int d=1;
return (a/d++);
}
void main ( )
{
int a [ ]={1, 2, 3, 4};
int i, s=0;
for (i=0; a[i];i++)
s+=add (a[i]);
printf("%d",s);
}
int add (int a)
{
static int d=1;
return (a/d++);
}
- 4
- 10
- 16
- None of these
115. The function strcmp(s1,s2) returns negative value if
- Length of s1 is less than s2
- Length of s2 is less than s1
- Length of s1 is less than or equal to s2
- Both s1 and s2 are same
116. Find the output
fun ( )
{
printf("Y");
}
#define fun () printf ("N")
void main ( )
{
fun ( );
(fun) ( );
}
fun ( )
{
printf("Y");
}
#define fun () printf ("N")
void main ( )
{
fun ( );
(fun) ( );
}
- YN
- NY
- Y
- N
117. Find the output
void main ( )
{
int a=5, b=10;
swap (a,b);
printf("%d %d", b, a);
}
swap (int x, int y)
{
int t=-x;
-x=-y;
y=t;
}
void main ( )
{
int a=5, b=10;
swap (a,b);
printf("%d %d", b, a);
}
swap (int x, int y)
{
int t=-x;
-x=-y;
y=t;
}
- 5 10
- 10 5
- -5 -10
- Compilatio error
118. Find the output
void main ( )
{
void evaluate (int *);
int a[3] [3]={{0,}, {2,3}, {4, 5}};
evaluate ((int *)a);
}
void evaluate (int *e)
{
printf ("%d", * (e+3));
}
void main ( )
{
void evaluate (int *);
int a[3] [3]={{0,}, {2,3}, {4, 5}};
evaluate ((int *)a);
}
void evaluate (int *e)
{
printf ("%d", * (e+3));
}
- 4
- 2
- 0
- Compilation error
119. Find the output
void main ( )
{
int x;
x=compute (4);
printf("%d",x);
}
int compute (int n)
{
if (n<=1)
return 2;
else
return (compute (n-2)*
compute (n-1));
}
void main ( )
{
int x;
x=compute (4);
printf("%d",x);
}
int compute (int n)
{
if (n<=1)
return 2;
else
return (compute (n-2)*
compute (n-1));
}
- 10
- 8
- 16
- 32
120. Which memory variable share the memory location in different fframes in function recursion
- Auto
- Static
- Extern
- Typedef