Practice Question and Answer
8Q: What is the difference between the following declarations? extern int fun(); int fun(); 1562 05b5cc7dde4d2b419777515f8
5b5cc7dde4d2b419777515f8- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
There is no difference except for the fact that the first one gives a hint that the function fun() is probably in another source file.
Q: What would be the output of the following program? main() { extern int fun ( float ); int a; a = fun ( 3. 14 ); printf ("%d", a); } int fun ( aa ) float aa ; { return ( (int) aa ); } 905 05b5cc7dde4d2b419777515f7
5b5cc7dde4d2b419777515f7- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
Error occurs because we have mixed the ANSI prototype with K & R style of function definition. When we use ANSI prototype for a function and pass a float to the function it is promoted to a double. When the function accepts this double into a float a type mismatch occurs hence the error. The remedy for this error could be to define the function as : int fun (float aa) { .... }
Q: Point out the error, if any, in the following program. main() { int ( *p )() = fun; ( *P ) (); } fun () { Printf ( "\nLoud and clear" ); } 1792 05b5cc7dde4d2b419777515f6
5b5cc7dde4d2b419777515f6- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
Here we are initalising the function pointer p to the address of the function fun(). But during this initialisation the function has not been defined. Hence an error. To eliminate this error add the prototype of the fun() before declaration of p, as shown below: extern int fun(); or simply int fun();
Q: Point out the error, if any, in the while loop. main() { int i = 1; while () { printf ( "%d", i++); if (i >10) break ; } } 1503 05b5cc7dde4d2b419777515f5
5b5cc7dde4d2b419777515f5- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
The condition in the while loop is a must.
Q: Point out the error, if any, in the following program. main() { int i = 4, j = 2; switch(i) { case 1 : printf (''\n To err is human, to forgive is against company policy."); break; case j : printf (''\n if you have nothing to do, don't do it here."); break; } } 2177 05b5cc7dde4d2b419777515f4
5b5cc7dde4d2b419777515f4- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
Constant expression required in the second case, we cannot use j.
Q: Rewrite the following set of statements using conditional operators. int a =1, b ; if ( a > 10 ) b = 20; 1472 05b5cc7dde4d2b419777515f3
5b5cc7dde4d2b419777515f3- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
int a = 1, b , dummy; a > 10 ? b = 20 : dummy =1; Note that the following would not have worked: a > 10 ? b = 20 : ;;
Q: What would be the output of the following program? main() { static int a[20]; int i = 0; a[i] = i++; printf ("\n%d%d%d", a[0], a[1], i); } 1897 05b5cc7dde4d2b419777515f2
5b5cc7dde4d2b419777515f2- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
0 0 1 That's what some of the compilers would give. But some other compiler may give a different answer. The reason is, when a single expression causes the same object to be modified and then inspected the behaviour is undefined.
Q: What would be the output of the following program? main() { int i=2 ; printf ("\n%d%d", ++i, ++i ); } 1637 05b5cc7dde4d2b419777515f1
5b5cc7dde4d2b419777515f1- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
Output may vary from compiler to compiler. The order of evaluation of the arguments to a function call is unspecified.

