Welcome Guest | Sign in | Register

Home > C Programming > Functions > Questions and Answers

01. What will the code below print when it is executed?
#include
void func()
{
int x = 0;
static int y = 0;
x++; y++;
printf( "%d -- %d\n", x, y );
}

int main()
{
func();
func();
return 0;
}
A. 1 -- 1
1 – 1
B. 1 -- 1
2 – 1
C. 1 -- 1
2 – 2
D. 1 -- 1
1 -- 2

Answer and Explanation

Answer: 1 -- 1
1 -- 2

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. What is the output of the following code?
#include
void main()
{
int s=0;
while(s++<10)>
# define a 10
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
}
A. 10..10 B. 10..50
C. Error D. 0

Answer and Explanation

Answer: Error

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. What is the output of the following code?
main()
{
int i=1;
while (i<=5) { printf("%d",i); if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}
A. Compiler error: Undefined label 'here' in function main B. PP
C. 1, 2, 3, 4, 5 D. None of these

Answer and Explanation

Answer: Compiler error: Undefined label 'here' in function main

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.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. What is the output of the following code?
main()
{
show();
}
void show()
{
printf("I'm the greatest");
}
A. I'm the greatest B. Compiler error: Type mismatch in re-declaration of show.
C. null D. None of these

Answer and Explanation

Answer: Compiler error: Type mismatch in re-declaration of show.

Explanation:
When the compiler sees the function show it doesn't know anything about it. So the default return type (i.e. int) is assumed. But when compiler sees the actual definition of show mismatch occurs since it is declared as void. Hence it gives compiler error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. What is the output of the following code?
main()
{
int i;
i = abc();
printf("%d",i);
}
abc()
{
_AX = 1000;
}
A. 10 B. 100
C. 1000 D. 0

Answer and Explanation

Answer: 1000

Explanation:
Normally the return value from the function is through the information from the accumulator. Here _AH is the pseudo global variable denoting the accumulator. Hence, the value of the accumulator is set 1000 so the function returns value 1000.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. What are the following notations of defining functions known as?
i. int abc(int a,float b)
{
/* some code */
}

ii. int abc(a,b)
int a; float b;
{
/* some code*/
}
A. Passing parameters B. Passing arguments
C. i. Kernighan & Ritche notation
ii. ANSI C notation
D.  i. ANSI C notation
ii. Kernighan & Ritche notation

Answer and Explanation

Answer:  i. ANSI C notation
ii. Kernighan & Ritche notation

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. What is the output of the following code?
int swap(int *a,int *b)
{
*a=*a+*b;*b=*a-*b;*a=*a-*b;
}
main()
{
int x=10,y=20;
swap(&x,&y);
printf("x= %d y = %d\n",x,y);
}
A. x = 10 y = 10 B. x = 20 y = 20
C. x = 02 y = 01 D. x = 20 y = 10

Answer and Explanation

Answer: x = 20 y = 10

Explanation:
This is one way of swapping two values. Simple checking will help understand this.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. What is the output of the following code?
void ( * abc( int, void ( *def) () ) ) ();
A. null B. Returns float
C. Returns void D. Returns int

Answer and Explanation

Answer: Returns void

Explanation:
abc is a ptr to a function which takes 2 parameters .(a). An integer variable (b). A ptr to a funtion which returns void. The return type of the function is void.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. Which is not a proper prototype?
A. int funct(char x, char y); B. double funct(char x)
C. void funct(); D. char x();

Answer and Explanation

Answer: double funct(char x)

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. What is the return type of the function with prototype: "int func(char x, float v, double t);"
A. char B. int
C. float D. double

Answer and Explanation

Answer: int

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.