C Programming Quiz Set 5
This quiz is based on C programming question asked in GATE exams. This quiz is helpful for aspiring candidates of GATE, UGC NET and other competitive exams.
Congratulations - you have completed .
You scored %%SCORE%% out of %%TOTAL%%.
Your performance has been rated as %%RATING%%
Your answers are highlighted below.
Question 1 |
Choose the correct option to fill ?1 and ?2 so that the program below prints an input string in reverse order. Assume that the input string is terminated by a new line character.
void reverse(void){ int c; if(?1) reverse(); ?2 } main(){ printf("Enter Text"); printf("\n"); reverse(); printf("\n"); }[GATE 2008, 2 Marks]
?1 is (getchar() != '\n') ?2 is getchar(c) | |
?1 is (c = getchar()) != '\n') ?2 is getchar(c) | |
?1 is (c != '\n') ?2 is putchar(c) | |
?1 is ((c = getchar()) != '\n') ?2 is putchar(c) |
Question 2 |
The following program is to be tested for statement coverage:
begin if(a == b) { S1; exit;} else if(c == d){S2;} else {S3; exit;} S4; endThe test cases \(T_1\), \(T_2\), \(T_3\) and \(T_4\) given below are expressed in terms of the properties satisfied by the values of variables \(a\), \(b\), \(c\) and \(d\). The exact values are not given.
- \(T_1\): \(a\), \(b\), \(c\) and \(d\) are all equal.
- \(T_2\): \(a\), \(b\), \(c\) and \(d\) are all distinct.
- \(T_3\): \(a = b\), \(c\ ne d\)
- \(T_4\): \(a \ne b\), \(c = d\)
\(T_1\), \(T_2\), \(T_3\) | |
\(T_2\), \(T_4\) | |
\(T_3\), \(T_4\) | |
\(T_1\), \(T_2\), \(T_4\) |
Question 3 |
Consider the following recursive C function that takes two arguments.
unsigned int foo(unsigned int n, unsigned int r) { if(n > 0) return (n % r) + foo(n / r, r); else return 0; }What is the return value of the function
foo
when it is called as foo(345, 10)
? [GATE 2011, 2 Marks]345 | |
12 | |
5 | |
3 |
Question 4 |
Consider problem 3
What is the return value of the function foo when it is called as foo(513, 2)? [GATE 2011, 2 Marks]
What is the return value of the function foo when it is called as foo(513, 2)? [GATE 2011, 2 Marks]
9 | |
8 | |
5 | |
2 |
Question 5 |
What will be the output of the following C program statement?
char inChar = 'A'; switch(inChar) { case 'A' : printf("Choice A\n"); case 'B' : case 'C' : printf("Choice B"); case 'D' : case 'E' : default : printf("No Choice"); }[GATE 2012, 1 Marks]
No Choice | |
Choice A | |
Choice A Choice B No Choice | |
Program gives no output as it is erroneous. |
Question 6 |
Consider the following C code segment.
int a, b, c = 0; void prtFun(void); 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? [GATE 2012, 2 Marks]
3 1 4 1 4 2 | |
4 2 6 1 6 1 | |
4 2 6 2 2 0 | |
3 1 5 2 5 2 |
Question 7 |
Consider problem 6
What output will be generated by the given code segment if:
What output will be generated by the given code segment if:
- Line 1 is replaced by
auto int a = 1;
- Line 2 is replaced by
register int a = 2;
[GATE 2012, 2 Marks]
3 1 4 1 4 2 | |
4 2 6 1 6 1 | |
4 2 6 2 2 0 | |
4 2 4 2 2 0 |
Question 8 |
Consider the following program in C language:
#include<stdio.h> main() { int i; int *pi = &i; scanf("%d",pi); printf("%d\n", i + 5); }Which one of the following statement is TRUE? [GATE 2014 (SET 1), 2 Marks]
Compilation fails. | |
Execution results in a run time error. | |
On execution, the value printed is 5 more than the address of variable i; | |
On execution, the value printed is 5 more than the integer value entered. |
Question 9 |
Consider the following pseudo code.
D = 2 for i = 1 to n do for j = i to n do for k = j+1 to n do D = d * 3What is the total number of multiplication to be performed? [GATE 2014 (SET 1), 2 Marks]
Half of the product of the 3 consecutive integers. | |
One-third of the product of the 3 consecutive integers.. | |
one-sixth of the product of the 3 consecutive integers. | |
None of the above. |
Question 10 |
Suppose \(n\) and \(p\) are unsigned int variables in a C program. We wish to set \(p\) to \(n \choose x\). If \(n\) is large, which one of the following statement is most likely to set \(p\) correctly. [GATE 2014 (SET 2), 1 Marks]
p = n*(n-1)*(n-2)/6; | |
p = n*(n-1)/2*(n-2)/3; | |
p = n*(n-1)/3*(n-2)/2; | |
p = n*(n-1)*(n-2)/6.0; |
Once you are finished, click the button below. Any items you have not completed will be marked incorrect.
There are 10 questions to complete.