C- Functions Question and Answer
C- Functions Question and Answer
121. Function is used to
- Convert a generic style program to modular style
- Convert a modular style program to object oriented style
- Convert a program into function oriented
- None of the above
122. Find the outputt
void main ( )
{
char c[ ] = "A.P.J";
display (c);
}
display (char *p)
{
while (*p!='\0')
{
if (*p++!='.')
printf("%c",*p);
p++;
}
}
void main ( )
{
char c[ ] = "A.P.J";
display (c);
}
display (char *p)
{
while (*p!='\0')
{
if (*p++!='.')
printf("%c",*p);
p++;
}
}
- A.P.J
- A.P
- APJ
- None of these
123. Find the output
void main ( )
{
int i=3, j;
j=add (++i);
printf("%d %d",i,j);
}
add (ii)
int ii;
{
ii++;
printf("%d ",ii);
}
void main ( )
{
int i=3, j;
j=add (++i);
printf("%d %d",i,j);
}
add (ii)
int ii;
{
ii++;
printf("%d ",ii);
}
- Garbage 4 1
- 5 4 2
- 54 1
- None of these
124. Find the output
void insert ( char a[ ], int n)
{
int i,j;
for (i=j=0; a[i]!='\0';i++)
if (a [i]!=n)
a [j++]=a[i];
a[j]='\0';
}
void main ( )
{
char a[ ] = "justdoit";
insert (a, 't');
printf("%s", a);
}
void insert ( char a[ ], int n)
{
int i,j;
for (i=j=0; a[i]!='\0';i++)
if (a [i]!=n)
a [j++]=a[i];
a[j]='\0';
}
void main ( )
{
char a[ ] = "justdoit";
insert (a, 't');
printf("%s", a);
}
- justdoit
- jusdoi
- justtdoitt
- None of these
125. Find the output
void main ( )
{
int i, n, m, b, x [25];
int f1 (int, int, int j[25]);
for ( i=0; i<25; i++)
x[i]=i;
i=0;m=24;
b=f1 ( i, m, x);
printf("res %d\n", b);
}
int f1(int p, int q, int a[25])
{
int m1, m2;
if (q==0)
return (a[p])'
else
[
m1=f1 (p,q/2, a);
m2=f1 (p+q/2+1, q/2, a);
if (m1<m2)
return (m2);
else
return (m1);
}
}
void main ( )
{
int i, n, m, b, x [25];
int f1 (int, int, int j[25]);
for ( i=0; i<25; i++)
x[i]=i;
i=0;m=24;
b=f1 ( i, m, x);
printf("res %d\n", b);
}
int f1(int p, int q, int a[25])
{
int m1, m2;
if (q==0)
return (a[p])'
else
[
m1=f1 (p,q/2, a);
m2=f1 (p+q/2+1, q/2, a);
if (m1<m2)
return (m2);
else
return (m1);
}
}
- res 204
- res 12083
- res 202
- None of these
126. Function can return at a time
- One value
- More than one value
- Return nothing
- None of these
127. Function prototype is not required if return type is
- int
- float
- struct
- None of the above
128. find the output
void main ( )
{
int x;
x=3;
f (x);
printf ("MAIN");
}
f (int n)
{
printf("F");
if (n !=0)
f (n-1);
}
void main ( )
{
int x;
x=3;
f (x);
printf ("MAIN");
}
f (int n)
{
printf("F");
if (n !=0)
f (n-1);
}
- FFFMAIN
- FFFFMAN
- FFMAIN
- None of these
129. Find the output
void main ( )
{
auto int i=0;
printf("%d ",i);
{
int i=2;
printf("%d ",i);
{
int i=2;
printf("%d ",i);
{
i+=1;
printf("%d ",i);
}
printf ("%d ",i);
}
printf ("%d ",i);
printf("%d ",ret10 ( ) );
printf("%d ",ret10 ( ) );
}
int ret10 ( )
{
static int i=10;
i+=1;
return (i);
}
void main ( )
{
auto int i=0;
printf("%d ",i);
{
int i=2;
printf("%d ",i);
{
int i=2;
printf("%d ",i);
{
i+=1;
printf("%d ",i);
}
printf ("%d ",i);
}
printf ("%d ",i);
printf("%d ",ret10 ( ) );
printf("%d ",ret10 ( ) );
}
int ret10 ( )
{
static int i=10;
i+=1;
return (i);
}
- 0 2 3 3 3 11 11
- 0 2 3 3 0 11 11
- 0 2 3 3 3 11 12
- 0 2 3 3 0 11 12
130. Find the output
f (int x, int *y)
{
x=*(y)+=2;
}
void main ( )
{
static int a[5]={2, 4, 6, 8, 10};
int i, b=5;
for (i=0; i<5;i++)
{
f (a[i], &b);
}
printf("%d %d\n", a[i], b);
}
f (int x, int *y)
{
x=*(y)+=2;
}
void main ( )
{
static int a[5]={2, 4, 6, 8, 10};
int i, b=5;
for (i=0; i<5;i++)
{
f (a[i], &b);
}
printf("%d %d\n", a[i], b);
}
- 10 15
- 8 15
- Garbage 15
- None of these