Sunday, July 12, 2009

Comp programming basic question C++?

what is


Static_Cast%26lt;int%26gt; (18.9%3)





if a=2 b= 6


int c= ++a + b++;


what are the values of


a, b and c?

Comp programming basic question C++?
As to you first question, it is static_cast%26lt;int%26gt;, lower case, not upper.





You can't do





static_cast%26lt;int%26gt; (18.9 % 3);





because the mod operator does not work on floating point values. You can break it up like this though:





int x = static_cast%26lt;int%26gt; (18.9);


cout %26lt;%26lt; x %26lt;%26lt; endl;


x %= 3;


cout %26lt;%26lt; x %26lt;%26lt; endl;





and see that x gets truncated to 18 and since 3 divides evenly into 18 the remainder (mod) is 0.
Reply:a=3


b=7


c=9





a is incremented before the addition of a+b and b is incremented after the addition so a = 3 + 6
Reply:The Typical values are:


a=3


b=7


c=9


But sometimes the values are diff from the above mentioned one bcos it depends on the compiler being used i.e the compiler code,design and priority for post and pre increment.
Reply:++a means the value of the a is incremented first


a=a+1


a=2+1


a=3





b=6


b is added first after adding it is incremented not before


means


3+6


when this line is executed


then the value of b increase 1 and become 7for next step





if u not understand then tell me i will explain you

floral arrangements

No comments:

Post a Comment