|
Functions
|
|
[Q001]
The following code is not well-written. What does the program do ?
void main()
{
int a=1,b=2;
printf("%d",add(a,b));
}
int add(int a,int b)
{
return (a+b);
}
|
|
(a)Run-Time Error (b)Compile-Time Error (c)3 (d)None of these
Ans. (b)
|
|
|
|
[Q002] What will be the output of the following program :
int add(int a,int b)
{
int c=a+b;
}
void main()
{
int a=10,b=20;
printf("%d %d %d",a,b,add(a,b));
}
|
|
(a)10 20 0 (b) Compile-Time Error (c)10 20 30 (d)
None of these
Ans. (c)
|
|
|
[Q003] What will be the output of the following program :
int add(int a,int b)
{
int c=a+b;
return;
}
void main()
{
int a=10,b=20;
printf("%d %d %d",a,b,add(a,b));
}
|
|
(a)10 20 0 (b)Compile-Time Error (c)10 20 30 (d)None of these
Ans. (c)
|
|
|
[Q004] What will be the output of the following program :
void main()
{
int add(int,int);
int a=7,b=13;
printf("%d",add(add(a,b),add(a,b)));
}
int add(a,b)
int a,b;
{
return (a+b);
}
|
|
(a)Compile-Time error (b)20 (c)40 (d)None of these
Ans. (c)
|
|
|
[Q005] What will be the output of the following program :
int add(a,b)
{
int c=a+b;
return c;
}
void main()
{
int a=10,b=20;
printf("%d",add(a,b));
}
|
|
(a)30 (b)Compile-Time Error (c)0 (d)None of these
Ans. (a)
|
|
|
[Q006] What will be the output of the following program :
int funct2(int b)
{
if (b == 0)
return b;
else
funct1(b--);
}
int funct1(int a)
{
if (a == 0)
return a;
else
funct2(a--);
}
void main()
{
int a=7;
printf("%d",funct1(a));
}
|
|
(a)0 (b)Compile-Time Error (c)Infinite Loop (d)7
Ans. (c)
|
|
|
|
[Q007] What will be the output of the following program :
int funct2(int b)
{
if (b == 0)
return b;
else
funct1(--b);
}
int funct1(int a)
{
if (a == 0)
return a;
else
funct2(--a);
}
void main()
{
int a=7;
printf("%d",funct1(a));
}
|
|
(a)0 (b)Compile-Time Error (c)Infinite Loop (d)7
Ans. (a)
|
|
|
|
[Q008] What will be the output of the following program :
int funct1(int a)
{{;}{{;}return a;}}
void main()
{
int a=17;
printf("%d",funct1(a));
}
|
|
(a)0 (b)Compile-Time Error (c)17 (d)None of these
Ans. (c)
|
|
|
[Q009] What will be the output of the following program :
int funct1(int a)
{
if (a)
return funct1(--a)+a;
else
return 0;
}
void main()
{
int a=7;
printf("%d",funct1(a));
}
|
|
(a)7 (b)21 (c)28 (d)None of these
Ans. (c)
|
|
|
|
[Q010] What will be the output of the following program :
int compute(int a,int b)
int c;
{
c=a+b;
return c;
}
void main()
{
int a=7,b=9;
printf("%d",compute(a,b));
}
|
|
(a)Compile-Time Error (b)16 (c)None of these
Ans. (a)
|
|
|
[Q011]What will be the output of the following program :
int a=10;
void compute(int a)
{
a=a;
}
void main()
{
int a=100;
printf("%d ",a);
compute(a);
printf("%d",a);
}
|
|
(a)10 10 (b)Compile-Time Error (c)100 100 (d)100 10
Ans. (c)
|
|
|
|
[Q012] What will be the output of the following program :
int funct(char ch)
{
ch=ch+1;
return ch;
}
void main()
{
int a=127;
printf("%d %d",a,funct(a));
}
|
|
(((a)Compile-Time Error (b)127 128 (c)127 -128 (d)None of these
Ans. (cAns. (c)
|
|
|
|
[Q013] What will be the output of the following program :
char funct(int val)
{
char ch=val;
return ch;
}
void main()
{
float a=256.25;
printf("%d",funct(a));
}
|
|
(a)0 (b)256.25 (c)256 (d)None of these
Ans. (a)
|
|
|
[Q014]What will be the output of the following program :
auto int a;
void changeval(int x)
{
a=x;
}
void main()
{
a=15;
printf("%d",a);
changeval(75);
printf("%d",a);
}
|
|
(a)Compile-Time Error (b)15 75 (c)15 15 (d)None of these
Ans. (a)
|
|
|
|
[Q015What will be the output of the following program :
int val;
static int funct()
{
return val*val;
}
void main()
{
val=5;
funct();
val++;
printf("%d",funct());
}
|
|
(a)Compile-Time Error (b)25 (c)36 (d)None of these
Ans. (c)
|
|
|
|
[Q016] What will be the output of the following program :
static int funct(int val)
{
static int sum;
sum+=val;
return sum;
}
void main()
{
int i,n=9;
for (i=1; i<n--; i++)
funct(i*2);
printf("%d",funct(0));
}
|
|
(a)20 (b)0 (c)30 (d)None of these
Ans. (a)
|
|
|
[Q017]What will be the output of the following program :
void print(int a[],...)
{
while (*a != -1)
printf("%d",*a++);
}
void main()
{
int a[]={1,2,3,4,5,-1};
print(a,5,6,7,8,9,-1);
}
|
|
(a)Compile-Time Error (b)Run-Time Error (c)12345 (d)56789
Ans. (c)
|
|
|
[Q018] What will be the output of the following program :
void print(int *);
void print(int *);
void main()
{
int x=100;
print(&x);
}
void print(int *a)
{
printf("%d",*a);
}
|
|
(a)Compile-Time Error (b)Run-Time Error (c)100 (d)None of these
Ans. (c)
|
|
|
[Q019] What will be the output of the following program :
void main()
{
void funct1(void);
void funct2(void);
clrscr();
funct1();
}
void funct1(void)
{
printf("Ocean of ");
funct2();
}
void funct2(void)
{
printf("Knowledge");
}
|
|
(a)Compile-Time Error (b)Run-Time Error (c)Ocean of Knowledge (d)None of these
Ans. (a)
|
|
|
[Q020] What will be the output of the following program :
static int count=1;
void funct3(void)
{
printf("%d",++count);
}
void funct2(void)
{
printf("%d",count);
funct3();
}
void funct1(void)
{
printf("Counting...%d",count++);
funct2();
}
void Main()
{
funct1();
}
|
|
(a)Compile-Time Error (b)Counting...123 (c)Counting...111 (d)Counting...112
Ans. (a) Since main() is different from Main() i.e. linker error
|
|
Back
|
|
Next
|
|