1.  What will be the output of the program?
#include
int check(int);
int main()
{
int i=45, c;
c = check(i);
printf(‘’%d\n’’, c);
return 0;
}
int check(int ch)
{
if(ch >= 45)
return 100;
else
return 10;
}


100
10
1
0.


Answer

 Option

Step 1: int check(int); This prototype tells the compiler that the function check() accepts one integer parameter and returns an integer value. Step 2: int l=45, c; The variable i and c are declared as an integer type and i is initialized to 45. The function check(i) return 100 if the given value of variable i is >=(greater than or equal to) 45, else it will return 10. Step 3: c = check(i); becomes c = check(45); The function check() return 100 and it get stored in the variable c.(c = 100) Step 4: printf(''%d\n'', c); It prints the value of variable c. Hence the output of the program is '100'.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

2.  What is the output of the following code?
main()
{
int a=1, b=10;
swap(a,b);
printf(‘’\n%d%d’’, a,b);
}
swap(int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
}


11
110
101
None of these


Answer

 Option

The 'call by value' method is applied in this program. Here the data is passed by value in the main(). So the variables are not changed.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

3.  What does the following function print?
func(int i)
{
if(i%2) return 0;
else return 1;
}
main()

{
int i=3;
i=func(i);
i=func(i);
printf(''%d'', i);
}


3
1
0.
2


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

4.  What will be printed when this program is executed ?
int f(int x)
{
if(x <= 4)
return x;
return f(--x);
}
void main()
{
printf(%d, f(7));
}


4 5 6 7
1 2 3 4
4
syntax error


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

5.  What will be the output of the program?
#include
int fun(int i)
{
i++;
return i;
}
int main()
{
int fun(int);
int i=3;
fun(i=fun(fun(i)));
printf(''%d\n'', i);
return 0;
}


5
4
Error
Garbage value


Answer

 Option

Step 1: int fun(int); This is prototype of function fun(). It tells the compiler that the function fun() accept one integer parameter and returns an integer value. Step 2: int i=3; The variable i is declared as an integer type and initialized to value 3. Step 3: fun(i=fun(fun(i)));. The function fun(i) increements the value of i by 1(one) and return it. Lets go step by step, => fun(i) becomes fun(3) is called and it returns 4. => i = fun(fun(i)) becomes i = fun(4) is called and it returns 5 and stored in variable i.(i=5) => fun(i=fun(fun(i))); becomes fun(5); is called and it return 6 and nowhere the return value is stored. Step 4: printf("%d\n", i); It prints the value of variable i.(5) Hence the output is '5'.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report