Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


1)
int i=5;
j=i++ + i++ + i++;
printf("%d",j);This code gives the answer 15.But if we
replace the value of the j then anser is different?why?

2)int i=5;
printf("%d",i++ + i++ + i++);
this givs 18.

Answers were Sorted based on User's Feedback



1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we ..

Answer / venu

i don't know the answer.
but here is the proble.
int i=5;
j=++i + ++i + ++i;
printf("%d",j);This code gives the answer 22.

How and What is the process?

Is This Answer Correct ?    62 Yes 32 No

1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we ..

Answer / raghu

In the first case
initially j=15 is assigned that is (5+5+5).then i gets incremented thrice.if we try to print i then i will be
8 (5 is incremented thrice).

In the second case
as we know that printf gets evaluated 4m right to left
that is pf("%d", 5++ + 5++ +5++);
that means 4m right to left 7+6+5=18
firstly i's value is 5 then it gets incremented 6 then 7.

Is This Answer Correct ?    42 Yes 14 No

1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we ..

Answer / gireesh

I have tried the second case in linux with gcc. But, the
output is 15 and not 18.

Is This Answer Correct ?    40 Yes 21 No

1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we ..

Answer / divakar

in the 1st case post increment will be done at the end of
the statement that is 15 is assigned to 'j' then 'i' will
increment 3 times bcoz 3 post increments r there.
in the later case first 15 assign to 'i' then increment
3 times and assign to 'i'

Is This Answer Correct ?    26 Yes 18 No

1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we ..

Answer / prasoon

both the codes possess undefined behaviour because the value
of i is changing more than once between two sequence points...

hence my answer is undefined behaviour

Is This Answer Correct ?    14 Yes 6 No

1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we ..

Answer / satyasaran

Remember increment operator is compiler depended.
1.
if u compiled in TC++ then u will get j=18
if u compile in VC++ then u will get j=15.
2.
if u compiled in TC++ then u will get j=18
if u compile in VC++ then u will get j=15.

Is This Answer Correct ?    14 Yes 11 No

1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we ..

Answer / amey

in the 1st case post increment will be done at the end of
the statement that is 15 is assigned to 'j' then 'i' will
increment 3 times bcoz 3 post increments r there.
in the later case first 15 assign to 'i' then increment
3 times and assign to 'i'

Is This Answer Correct ?    5 Yes 4 No

1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we ..

Answer / keerthan

Here, in first case, i=5, j=(i++)+ (i++) + (i++)............ i is added three times without incrementing because it is post incremented so... 5 is added with 5 and again with 5 answer is 15.
where as in second case... execution from right to left when it is done... initially i=5, first i++ this value is 5 then incremented so that 6 is added to 5... now is incremented again so 7 now 7+6+5 =18.

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Code Interview Questions

Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

0 Answers   IBM,


posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0;i<=3;i++) printf("%02x",(unsigned char) p[i]); } how is the output of this program is :: 0000ac40 please let me know y this output has come

2 Answers   GATE,


Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.

9 Answers   Microsoft,


char *someFun1() { char temp[ ] = “string"; return temp; } char *someFun2() { char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’}; return temp; } int main() { puts(someFun1()); puts(someFun2()); }

2 Answers  


given integer number,write a program that displays the number as follows: First line :all digits second line : all except the first digit . . . . Last line : the last digit

8 Answers  


main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }

2 Answers  


Write a program to check whether the number is prime and also check if it there i n fibonacci series, then return true otherwise return false

1 Answers   Cognizant, lenovo,


Write a program using one dimensional array to assign values and then display it on the screen. Use the formula a[i]=i*10 to assign value to an element.

1 Answers   Samar State University,


Write a c program to search an element in an array using recursion

1 Answers   Wipro,


write a c-program to display the time using FOR loop

3 Answers   HCL,


&#8206;#define good bad main() { int good=1; int bad=0; printf ("good is:%d",good); }

2 Answers  


how can i cast a char type array to an int type array

2 Answers  


Categories