void main()
{
int i,j=2;
for(i=0;i<3;i++)
if(j=i)
cout<<"Lotus ";
else
cout<<"Rose ";
}
Its result is Rose Lotus Lotus.. How? Explain it?

Answers were Sorted based on User's Feedback



void main() { int i,j=2; for(i=0;i<3;i++) if(j=i) cout<<"Lotus "; else co..

Answer / nc

In the assignment operations...if the assigned value is 0
then it denotes false and for any other number 1,2,3...it
denotes true.So for i=0 i.e j becomes 0 means condition
becomes false so it displays Rose and for rest of the values
of i it displays Lotus.

Is This Answer Correct ?    10 Yes 0 No

void main() { int i,j=2; for(i=0;i<3;i++) if(j=i) cout<<"Lotus "; else co..

Answer / pasha nitw

i think u confused at step 5
if(j=i) is different from if(j==i)
where as in if(j=i)
first i value assigned to j value for entire loop
then it cheks the expression.
according to this
if(0)
if(1)
if(2)
.
.
.
.

Is This Answer Correct ?    6 Yes 2 No

Post New Answer

More C++ Code Interview Questions

Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

3 Answers   TCS, Vimukti Technologies, Wipro,


write a program that can locate elements in array.

1 Answers  


Given 1 to n distinct random number of which n+1th element was duplicated. How do find the duplicate element and explain the time complexity of the algorithm.

0 Answers   Microsoft, NetApp,


what is the diffrence between ++x , x++ pleaaaaase ???

7 Answers  


A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect

0 Answers  






output for printf("printf");

0 Answers  


write a program to sort 'n' elemnts using bubble sort

1 Answers   IBM,


main(){int a=5,b 10,c=2, d;a=b c;d=++a=(--c)*2; printf("%d%d%d%d,a,b,c,d; return o;}

1 Answers  


Deriving time complexity of Binary tree and AVL tree, step by step.

4 Answers   NetApp,


write a program to perform generic sort in arrays?

0 Answers  


A research student is given a singly-linked list. Each node of the list has a color, which is either “Black” or “White”. He must find if there are more black nodes than white nodes, or vice versa. His advisor gives him 5,000Rs to buy a computer to do the work. He goes to the computer store and finds a slightly defective computer which costs a mere 3,000Rs. This computer has the small problem of not being able to do arithmetic. This means that he cannot use a counter to count the nodes in the list to determine the majority color. The computer is otherwise fully functional. He has the evil idea that he could buy the defective computer and somehow use it to do his work, so that he can use the rest of the money on enjoyment. Show how he can accomplish this amazing task. Write code for an algorithm called ‘findMajorityColor’ which takes a singly-linked list, L, with n nodes and returns the majority color among nodes of L. This algorithm should have the same asymptotic running time as counting the nodes (O(n)). Note: No arithmetic is allowed.

2 Answers  


write a program to convert temperature from fa height into celcius and vise versa,use modular programming

0 Answers   Jomo Kenyatta University,


Categories