C Aptitude Questions On Functions With
Answers
1. What is the output of the following program?
void f1()
{
int a=0;
++a;
printf(“n%d”,a);
}
int main()
++a;
printf(“n%d”,a);
}
int main()
{
int a=10;
f1();
f1();
f1();
printf(“%d”,a);
return 0;
int a=10;
f1();
f1();
f1();
printf(“%d”,a);
return 0;
}
Ans: 1 1 1 10
2. What is the output of the following program?
void f1()
{
static int s=5;
++s;
printf(“n%d”,s);
}
int main()
static int s=5;
++s;
printf(“n%d”,s);
}
int main()
{
f1();
f1();
printf(“%d”,s);
}
Ans: Error
f1();
f1();
printf(“%d”,s);
}
Ans: Error
3. What is the output of the following program?
void f1()
{
static int s=5;
++s;
printf(“n%d”,s);
}
int main()
static int s=5;
++s;
printf(“n%d”,s);
}
int main()
{
f1();
f1();
}
f1();
f1();
}
Ans: 6 7
4. What is the output of the following program?
void abc(int a)
{
++a;
}
void main()
++a;
}
void main()
{
int a=10;
abc();
abc();
printf(“%d”,a);
}
int a=10;
abc();
abc();
printf(“%d”,a);
}
Ans: a=10
5. What is the output of the following program?
void abc(int a)
{
++a;
}
void main()
++a;
}
void main()
{
int a=10;
abc(a);
abc(a);
printf(“%d”,a);
}
int a=10;
abc(a);
abc(a);
printf(“%d”,a);
}
Ans: a=10
6. What is the output of the following program?
void f1()
{
extern int g;
static int s=5;
int a;
++g;
a=s++;
printf(“n%d %d %d”,a,s,g);
if(a<=6)
f1();
printf(“n%d %d %d”,a,s,g);
}
void f2()
static int s=5;
int a;
++g;
a=s++;
printf(“n%d %d %d”,a,s,g);
if(a<=6)
f1();
printf(“n%d %d %d”,a,s,g);
}
void f2()
{
static int s;
int a;
a=++s;
++g;
printf(“n%d %d %d”,a,s,g);
if(a<=2)
f2();
printf(“n%d %d %d”,a,s,g);
}
int main()
static int s;
int a;
a=++s;
++g;
printf(“n%d %d %d”,a,s,g);
if(a<=2)
f2();
printf(“n%d %d %d”,a,s,g);
}
int main()
{
f1();
f2();
}
f1();
f2();
}
Ans: Error undefine symbol _g(Linking Error)
7. What is the output of the following program?
void abc(int a)
{
++a;
printf(“n%d”,a);
}
void main()
printf(“n%d”,a);
}
void main()
{
int a=10;
abc(++a);
abc(a++);
printf(“%d”,a);
}
Ans: 12 12 12
int a=10;
abc(++a);
abc(a++);
printf(“%d”,a);
}
Ans: 12 12 12
8. What is the output of the following program?
void abc(int a,int b)
{
printf(“n%d %d”,++a,++b);
}
void main()
printf(“n%d %d”,++a,++b);
}
void main()
{
int a=10;
abc(++a,a++);
abc(a++,++a);
printf(“%d”,a);
}
Ans: 13 11
14 14
14
int a=10;
abc(++a,a++);
abc(a++,++a);
printf(“%d”,a);
}
Ans: 13 11
14 14
14
9. What is the output of the following program?
void xyz(int p1,int *p2)
{
++p1;
++*p2
printf(“n%d %d”,p1,*p2);
}
void main()
++*p2
printf(“n%d %d”,p1,*p2);
}
void main()
{
int a=10;
xyz(a++,&a);
xyz(a++,&a);
printf(“n%d”,a);
}
Ans: 11 12
13 14
14
int a=10;
xyz(a++,&a);
xyz(a++,&a);
printf(“n%d”,a);
}
Ans: 11 12
13 14
14
10. What is the output of the following program?
void xyz(int p1,int p2)
{
++p1;
++p2;
printf(“n%d %d”,p1,p2);
}
void main()
++p2;
printf(“n%d %d”,p1,p2);
}
void main()
{
int a=10;
xyz(a++,++*(&a));
xyz(a++,++*(&a));
printf(“n%d”,a);
}
Ans: 12 12
14 14
14
int a=10;
xyz(a++,++*(&a));
xyz(a++,++*(&a));
printf(“n%d”,a);
}
Ans: 12 12
14 14
14
11. What is the output of the following program?
void xyz(int p1,int *p2)
{
++p1;
++*p2
printf(“n%d %d”,p1,*p2);
if(p1<=12)
xyz(p1,p2);
printf(“n%d %d”,p1,*p2);
}
void main()
{
int a=10;
xyz(a++,&a);
xyz(a++,&a);
printf(“n%d”,a);
}
Ans: 11 12
12 13
13 14
13 14
12 14
11 14
15 16
15 16
16
++*p2
printf(“n%d %d”,p1,*p2);
if(p1<=12)
xyz(p1,p2);
printf(“n%d %d”,p1,*p2);
}
void main()
{
int a=10;
xyz(a++,&a);
xyz(a++,&a);
printf(“n%d”,a);
}
Ans: 11 12
12 13
13 14
13 14
12 14
11 14
15 16
15 16
16
12. What is the output of the following program?
#include<stdio.h>
void main()
{
int a=1;
void xyz(int,int);
xyz(++a,a++);
xyz(a++,++a);
printf(“n%d”,a);
}
void xyz( int x,int y)
{
printf(“n%d %d”,x,y);
}
Ans: 3 1
4 4
5
{
int a=1;
void xyz(int,int);
xyz(++a,a++);
xyz(a++,++a);
printf(“n%d”,a);
}
void xyz( int x,int y)
{
printf(“n%d %d”,x,y);
}
Ans: 3 1
4 4
5
13. What is the output of the following program?
#include<stdio.h>
void display(int a)
{
printf(“n%d”,a);
if(–a)
display(a);
printf(“n%d”,a);
}
void main()
{
display(4);
}
Ans: 4 3 2 1 0 1 2 3
{
printf(“n%d”,a);
if(–a)
display(a);
printf(“n%d”,a);
}
void main()
{
display(4);
}
Ans: 4 3 2 1 0 1 2 3
14. What is the output of the following program?
#include<stdio.h>
void xyz(int x)
{
printf(“n%d”,x);
if(x)
xyz(x-1);
printf(“n%d”,x);
}
void abc(int a)
{
printf(“n%d”,a);
xyz(a);
if(a)
abc(a-1);
printf(“n%d”,a);
}
void main()
{
abc(2);
}
{
printf(“n%d”,x);
if(x)
xyz(x-1);
printf(“n%d”,x);
}
void abc(int a)
{
printf(“n%d”,a);
xyz(a);
if(a)
abc(a-1);
printf(“n%d”,a);
}
void main()
{
abc(2);
}
Ans: 2————>abc
2 1 0 0 1 2–>xyz
1————>abc
1 0 0 1——>xyz
0————>abc
0 0———->xyz
0 abc
1 abc
2 abc
2 1 0 0 1 2–>xyz
1————>abc
1 0 0 1——>xyz
0————>abc
0 0———->xyz
0 abc
1 abc
2 abc
No comments:
Post a Comment