3 votes 3 votes What is the output of the following program? #include<stdio.h> void main() { int n=3, i=0; do { n=n++; i++; } while(i!=3); printf(“%d\n”, n); } Programming in C programming + – Sourabh Kumar asked Jul 20, 2016 • edited Sep 25, 2016 by go_editor Sourabh Kumar 626 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes I think it will be 3 In line with post increment n=n++; before assigning updated value to n (ie n+1) n will be assigned with old value (ie 3) n will be never changed even if the loop runs for infinite times sh!va answered Jul 21, 2016 • edited Jul 21, 2016 by sh!va sh!va comment Share Follow See all 3 Comments See all 3 3 Comments reply srestha commented Jul 21, 2016 reply Follow Share n is assigning 3 and then 3++ Are u telling that will causing problem for not increment the value of n? As constant cannot take ++ operator? 0 votes 0 votes Sourabh Kumar commented Jul 21, 2016 reply Follow Share @shiva: n=n++; will be interpreted as 2 lines 1st n=n//3 will assign to n. 2nd n=n+1;// then it will be incremented. Then i±± will happen. 0 votes 0 votes sh!va commented Jul 21, 2016 reply Follow Share @Sourab kumar: Sir, I checked by executing code.. I am getting answer as 3 Value of n is not changing 0 votes 0 votes Please log in or register to add a comment.