Note 1
##### Take Note:

Take a note while surfing.

##### Note With Ink

Give your Note a Colorful Tag.

##### Easy to Access

Stay on same information and in Sync wherever you are.

Note 2
##### Take Note:

Organize your information,It may take Shape.

##### Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3
##### Take Note:

Don't Let information to miss,Because it take shape

##### Note With Ink

Simple an Easy Way to take a note.

##### Easy to Access

Get the same in next visit.

# C Programming :: Functions

Home > C Programming > Functions > General Questions

#### Co. Cloud

1. What is the output of the following problem ?

#include
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));
}

| | | |

Explanation:

Here is no explanation for this answer

Workspace

Tags:  No Tags on this question yet!

2. What is the output of the following problem ?

#include
int main()
{
int j;
for(j=0;j<3;j++)
foo();
return 0;
}
foo() {
static int i = 10;
i+=10;
printf("%d",i);
}

| | | |

Explanation:

Here is no explanation for this answer

Workspace

Tags:  No Tags on this question yet!

3. What is the output of the following problem ?

#include

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));
}

| | | |

Explanation:

Here is no explanation for this answer

Workspace

Tags:  No Tags on this question yet!

4. What is the output of the following 'C' program?

aaa() {
printf("hi");
}
bbb() {
printf("hello");
}
ccc() {
printf("bye");
}
void main()
{
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2]();
}

| | | |

Explanation:

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

Workspace

Tags:  No Tags on this question yet!

5. What is the output of the following 'C' program?

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;
}

| | | |

Explanation:

Here is no explanation for this answer

Workspace

Tags:  No Tags on this question yet!

6. void main()
{
printf("%p",main);
}

| | | |

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

Tags:  Capgemini

7. int main()
{
show();
return 0;
}
void show()
{
printf("I'm the greatest");
}

| | | |

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 compiler sees the actual definition of show mismatch occurs since it is declared as void. Hence the error.

Workspace

Tags:  Capgemini

8. #include
int main()
{
int i=_l_abc(10);
printf("%d\n",--i);
return 0;
}
int _l_abc(int i)
{
return(i++);
}

| | | |

Explanation:

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

Workspace

Tags:  No Tags on this question yet!

9. #include
int main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}

| | | |

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

Tags:  No Tags on this question yet!

10. #include
int AX = 0;
int main()
{
int i=0;
i = abc();
printf("%d",i);
return 0;
}
abc()
{
AX = 1000;
return AX;
}

| | | |

Explanation:

Here is no explanation for this answer

Workspace

Tags:  No Tags on this question yet!