# C Programming :: Functions

Home > Technical Aptitude > C Programming > Functions > General Questions

NA
SHSTTON
4
Solv. Corr.
5
Solv. In. Corr.
9
Attempted
0 M:0 S
Avg. Time

1 / 47

What is the output of the following problem ?
#include<stdio.h>
int main()
{
int j,ans;
j = 4;
ans = count(4);
printf("%d\n",ans);
return 0;
}
int count(int  i)
{
if ( i < 0)
return(i);
else
return( count(i-2) + count(i-1));
}

A-18

B18

C8

DCompilation Error

ENo output

| | | Asked In |

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
4
Solv. Corr.
7
Solv. In. Corr.
11
Attempted
0 M:0 S
Avg. Time

2 / 47

What is the output of the following problem ?
#include<stdio.h>
int main()
{
int j;
for(j=0;j<3;j++)
foo();
return 0;
}
foo() {
static int i = 10;
i+=10;
printf("%d",i);
}

A20 20 20

B20 30 40

C10 10 10

DNone of these

| | | Asked In |

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
9
Solv. Corr.
2
Solv. In. Corr.
11
Attempted
0 M:0 S
Avg. Time

3 / 47

What is the output of the following problem ?
#include<stdio.h>

int main() {
int factorial(int n);
int i,ans;
ans = factorial(5);
printf("\nFactorial by recursion  = %d\n", ans);
return 0;
}
int factorial(int n)
{
if (n <= 1)
return (1);
else
return ( n * factorial(n-1));
}

A120

B5

C1

DNoneof these

| | | Asked In |

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
6
Solv. Corr.
5
Solv. In. Corr.
11
Attempted
0 M:0 S
Avg. Time

4 / 47

What is the output of the following 'C' program?
#include<stdio.h>
aaa() {
printf("hi");
}
bbb() {
printf("hello");
}
ccc() {
printf("bye");
}
void main()
{
int (*ptr)();
ptr=aaa;
ptr=bbb;
ptr=ccc;
ptr();
}

Ahi

Bbye

Caaa

DCompilation Error

ENone of these

| | | Asked In |

Explanation:

ptr is array of pointers to functions of return type int.ptr is assigned to address of the function aaa. Similarly ptr and ptr for bbb and ccc respectively. ptr() is in effect of writing ccc(), since ptr points to ccc.

Workspace

NA
SHSTTON
6
Solv. Corr.
6
Solv. In. Corr.
12
Attempted
0 M:0 S
Avg. Time

5 / 47

What is the output of the following 'C' program?
#include<stdio.h>
void main(){
int i=3,val;
val=f(i)+ +f(i=1)+ +f(i-1);
printf("%d",val);
}
int f(int num){
return num*5;
}

A20

B30

C21

D31

ECompilation error

| | | Asked In |

Explanation:

when f(i) executes first then i=5is there. therefore, f(5)return 15.

next i=1 then f(1) return 5

now f(1-1)=f(0) return 0

Workspace

NA
SHSTTON
7
Solv. Corr.
11
Solv. In. Corr.
18
Attempted
0 M:24 S
Avg. Time

6 / 47

What is the output of 'C program'
#include<stdio.h> void main()
{
printf("%p",main);
}

ACompilation error

BGarbage Value

DNone of these

| | | Asked In Capgemini |

Explanation:

Function names are just addresses (just like array names are addresses). main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They are printed as hexadecimal numbers

Workspace

NA
SHSTTON
8
Solv. Corr.
8
Solv. In. Corr.
16
Attempted
0 M:0 S
Avg. Time

7 / 47

What will be output of the following "c" code?
#include<stdio.h> int main()
{
show();
return 0;
}
void show()
{
printf("I'm the greatest");
}

ACompier error: Type mismatch in redeclaration of show.

BI', the greatest

DNone of these

| | | Asked In Capgemini |

Explanation:

When the compiler sees the function show it doesn't know anything about it. So the default return type (ie, int) is assumed. But when the compiler sees the actual definition of show mismatch occurs since it is declared as void. Hence there will be a warning, if you have set treat warning as error then option A will be, else option B will be. Here Option B will be correct.

Workspace

NA
SHSTTON
3
Solv. Corr.
6
Solv. In. Corr.
9
Attempted
0 M:0 S
Avg. Time

8 / 47

What will be output of the following "c" code?
#include<stdio.h>
int main()
{
int i=_l_abc(10);
printf("%d\n",--i);
return 0;
}
int _l_abc(int i)
{
return(i++);
}

A10

B8

C9

DCompilation error

ENone of these

| | | Asked In |

Explanation:

return(i++) it will first return i and then increments. i.e. 10 will be returned.

Workspace

NA
SHSTTON
6
Solv. Corr.
4
Solv. In. Corr.
10
Attempted
0 M:0 S
Avg. Time

9 / 47

What will be output of the following "c" code?
#include<stdio.h>
int main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}

ACompiler error: label 'here' used but not defined

BPP

C1 2 PP

DNone of these

| | | Asked In |

Explanation:

Labels have functions scope, in other words the scope of the labels is limited to functions. The label 'here' is available in function fun() Hence it is not visible in function main.

Workspace

NA
SHSTTON
6
Solv. Corr.
4
Solv. In. Corr.
10
Attempted
0 M:0 S
Avg. Time

10 / 47

What is the output of the following problem ?
#include<stdio.h>
int AX = 0;
int main()
{
int i=0;
i = abc();
printf("%d",i);
return 0;
}
abc()
{
AX = 1000;
return AX;
}

A0

B1000

C100

DGarbage Value

ECompilation Error

| | | Asked In |

Explanation:

Here is no explanation for this answer

Workspace