IQOD #4

Posts 1–8 of 8 · Page 1 of 1
IQOD #4
Sorry for the delay, busy day..

Consider the following program:
Code:
void main()
{
   //other code here that defines and calculates int i and int j
   //assume int i has somehow gotten a value of 10
   //assume int j has received a value of  20
   if(i=j)
   {
       return 0;
   }
   else
   {
     i += --j;
     j++;
   }

}
What are the values of I and J at the end of the program?
Quote Originally Posted by B1ackAnge1 View Post
Sorry for the delay, busy day..

Consider the following program:
Code:
void main()
{
   //other code here that defines and calculates int i and int j
   //assume int i has somehow gotten a value of 10
   //assume int j has received a value of  20
   if(i=j)
   {
       return 0;
   }
   else
   {
     i += --j;
     j++;
   }

}
What are the values of I and J at the end of the program?
void main returns 0 - wont compile

it says if(i=j) so they are both 20 at the end of the program(typo?)
if you meant if(i==j) then the ouput would be 29 for i since it then is i=10+(20-1) which is 29 and 20 for j as j gets increased by 1 after i gets set to --j.
Hmm my answer <!--

Wait what, that doesn't make sense. Shouldn't it be if (i == j). Because just = means it is assigning the value of j to i.

If this is in fact what you mean( = ), then wouldn't they both have the value of 20 at the end?

If you meant == then the answer would be i=20 j = 20
-->
Darn double Post, L'ignore
this one was too easy, but you'd be surprised how many people under the stress of an interview totally miss the = vs ==
Quote Originally Posted by B1ackAnge1 View Post
this one was too easy, but you'd be surprised how many people under the stress of an interview totally miss the = vs ==
it also has a return 0 when its a void ^^ compiler error :P
Quote Originally Posted by Hell_Demon View Post
it also has a return 0 when its a void ^^ compiler error :P
Yesh, but we don't have a compiler and we were told to assume it is correct.

Eitherway, it's nice to have an easy one once in a while xD. Boosts morale for the next 5 failures.

And yeah, under the stress of an interview i could totally understand missing that. Hmm but still. Oh well nvm, i suppose.
Quote Originally Posted by Hell_Demon View Post
it also has a return 0 when its a void ^^ compiler error :P
yeah that's for bonus points
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us