Practice Question and Answer

Q: What is the difference between the following declarations? extern int fun(); int fun(); 1562 0

  • Show AnswerHide Answer
  • Workspace

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.

  • Show AnswerHide Answer
  • Workspace

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) { ┬а .... }

  • Show AnswerHide Answer
  • Workspace

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();

  • Show AnswerHide Answer
  • Workspace

Answer :
Explanation :

The condition in the while loop is a must.

Q: Rewrite the following set of statements using conditional operators. int a =1, b ; if ( a > 10 ) b = 20; 1472 0

  • Show AnswerHide Answer
  • Workspace

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 : ;;

  • Show AnswerHide Answer
  • Workspace

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 0

  • Show AnswerHide Answer
  • Workspace

Answer :
Explanation :

Output may vary from compiler to compiler. The order of evaluation of the arguments to a function call is unspecified.

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully

      Report Error

    Please Enter Message
    Error Reported Successfully