C-Programming |Gate-2012|
1. What will be the output of the following C program segment? [GATE – 2012]
char inchar = 'A'; switch (inchar) { case 'A' : printf ("choice A n") ; case 'B' : printf ("choice B ") ; case 'C' : case 'D' : case 'E' : default: printf ("No Choice") ; } |
a. No choice
b. Choice A
c. Choice A
Choice B No choice
d. Program gives no output as it is erroneous
Answer : c)
2. Consider the following C code segment.
int a, b, c=0;
void prtFun (void);
main ()
{
static int a=1;
prtFun (); /* line*/
a+ =1;
prtFun ();
printf(“\n %d %d”,a,b);
}
void prtFun (void)
{
static int a=2;
int b=1; /* line*/
a+ = ++b;
printf (“\n %d %d”,a,b);
}
What output will be generated by the given code segment ? [GATE – 2012]
a. 3 1
4 1
4 2
b. 4 2
6 1
6 1
c. 4 2
6 2
2 0
d. 3 1
5 2
5 2
Answer : c)
3. Consider the following C program [GATE – 2012]
int a, b, c = 0; void prtFun (void); int main () { static int a = 1; /* line 1 */ prtFun(); a += 1; prtFun(); printf ( "n %d %d " , a, b) ; } void prtFun (void) { static int a = 2; /* line 2 */ int b = 1; a += ++b; printf (" n %d %d " , a, b); } What output will be generated by the given code segment? |
a. 3 1
4 1
4 2
b. 4 2
6 1
6 1
c. 4 2
6 2
2 0
d. 4 2
4 2
2 0
Answer : d)
C-Programming |Gate-2012|