UINT i,j;
i = j = 0;
i = ( i++ > ++j ) ? i++ : i--;

explain pls....

Answers were Sorted based on User's Feedback



UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / raj

1.we know that i=j=0 initially

2.then it will checks the non-incremented 'i' value(i.e 0)
with incremented 'j' value(i.e 1). So obviously condition
is falls.

3.now false statement has to be executed i.e (i--),before
executing this 'i' value is (i.e incremented value)'1'
after executing false condition(i.e i--)the value of 'i'
becomes '0'.

4.So the value of 'i' is '0'.

Is This Answer Correct ?    30 Yes 2 No

UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / vignesh1988i

UNIT i,j :
this line indicates that UNIT is an user defined data type. it may been declared as follows :

typedf int UNIT
we are making the code more readable

i=j=0 : indicates that the var. i and j are declared as 0

i=(i++>++j) ? i++ : i-- : the process here is

i++ is an post incrementation . if this is compared with any relational or any operaters first that value will be operated first and the 'i' will get incremented ........
but ++j if we take first thing it will increment the value and then operation will be performed

so when it is compared first i will be 0 and j will be 1 so 0 is not greater than 1. so false, so it will go to the statement after ':' so i-- is there so final value of i will be 0.

thank u

Is This Answer Correct ?    6 Yes 1 No

UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / dhatchina moorthy

r u guys nuts the person answered first is right.he
non-incremented 'i' value(i.e 0)
with incremented 'j' value(i.e 1). So condition
is falls.
so false part has to be executed i.e (i--),before
executing this 'i' value is (i.e incremented value)'1'
after executing false condition(i.e i-- her it doesn't
increment bcoz it is postfix operator)the value of 'i'
becomes '1'.

still having doubts, compile this program in ur pc.

Is This Answer Correct ?    5 Yes 1 No

UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / prem_mallappa

All answers are incorrect except this one.
Read c-faqs (Frequently asked questions about C)
The answer is unpredictable or implementation defined.

Is This Answer Correct ?    0 Yes 1 No

UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / chaneswara reddy

(i++ > j++) gives 0 because 0 > 0 is false so it return 0.
before returning 0 i is 1 ,but it is overwrite by 0.
In the Conditional operator false means ,it executes i++;
so i is 1.

Is This Answer Correct ?    3 Yes 19 No

Post New Answer

More C C++ Errors Interview Questions

Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a do...while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total . Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total . Use no variables other than n , k , and total .

3 Answers  


Given that two int variables, total and amount , have been declared, write a sequence of statements that: initializes total to 0 reads three values into amount , one at a time. After each value is read in to amount , it is added to the value in total (that is, total is incremented by the value in amount ). Instructor's notes: If you use a loop, it must be a for loop. And if you use a loop control variable for counting, you must declare it.

1 Answers   Google,


what is meant for variable not found?

3 Answers  


void main() { for(int i=0;i<5;i++); printf("%d",i); } What is the output?..

32 Answers   College School Exams Tests, CTS, HCL, iGate, SmartData,


what are the techniques for reducing the fragility of a memory bug?

1 Answers  






Answering Yes or No in C++...using only stdio.h and conio.h..........help me please...? here's must be the output of the program: Screen A Exam No. items Score 1 20 20 2 35 35 Another Entry? [Y] or [N] : Screen B: Record No. Student's Name: 1 Fernando Torres 2 Chuck Norris Note: if you press Y, the program must repeat the procedure in screen A, then if N, the program must proceed to the screen B....Please Help me out............

1 Answers  


write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;

0 Answers  


How to upgrade LOOP environment, I just mean, how can i make loop statement editable ? I just try some program using loop statement and checking it in multiple compilers. Every compiler showing different output, what's the wrong ? is it a compiler based problem, or loop based problem, tell me why ? and what will be the debugging process, for this kind of problem ?

1 Answers  


#include<>stdio.h> #include<>conio.h> { printf("hello"); void main() getch(); } what the out put of this program and why ......plz clear my answer

10 Answers   Wipro,


Using string functions write a program that will accept the name of the capital as input value and will display the corresponding country. ------------------------ Capitals Countries ------------------------ Capitals Countries Ottawa Canada Moscow Russia Rome Italy I can't not get it to run properly

1 Answers   AMA,


full c programming error question based problem

3 Answers   HCL, TCS,


Write a c-programe that input one number of four digits and find digits sum?

2 Answers  


Categories