Thursday, July 30, 2009

Choose the C++ statement which is equivalent to:?

printf("Area= %g \n", PI *Radius * Radius);





a. cout %26gt;%26gt;"Area = "%26gt;%26gt; PI * Radius * Radius %26gt;%26gt;endl;


b. cout %26lt;%26lt;"Area="%26lt;%26lt; PI * Radius * Radius %26lt;%26lt;endl


c. cout %26lt;%26lt;"Area="%26lt;%26lt; PI * Radius *Radius;


d. cout %26lt;%26lt; "Area= "%26lt;%26lt;PI * Radius *Radius %26lt;%26lt;endl;

Choose the C++ statement which is equivalent to:?
a
Reply:It's D. Don't listen to any of the people posting above me, they are all wrong.





In A, the wrong operator is being used (%26gt;%26gt; is used with input, not output).


In B, the semicolon is missing (would create a compilation error)


In C, the endline is missing (the C statment has an endline, \n, so this must too.)





So, D is the only correct choice
Reply:The correct answer is letter D.





REASON:


WRONG: A. Don't be confused between the "%26gt;%26gt;" operator and the "%26lt;%26lt;" operator. It is one of the PRIMARY RULES in C++ that cout always goes with the "%26lt;%26lt;" operator and cin always goes with the "%26gt;%26gt;" operator.





WRONG: B. In a C++ statement, always end the statement with a semicolon ( ; ).





WRONG: C. In your C statement, you placed an escape sequence which is "\n". This means that the program will need to continue execute on the second line. In C++, "endl" is interpreted by the machine as "continue executing the program on a new line" but letter C does not have an endl, though it will run but it doesn't satisfy to your instruction which is finding the "equivalence", making it an invalid answer.
Reply:A
Reply:the answer is "d"


No comments:

Post a Comment