1 1 vote What will be the output of the following program? #include <stdio.h> int main() { int i[] = {1,2,3}, j[] = {1,2,3}; int *p=i,*q=j; while ((*p++ = *q++) != 3) { printf("%d", *p); } return 0; } Programming in C programming-in-c data-structures pointers + – DTYDHTB 579 views answer comment Share Follow Print See all 4 Comments 4 4 Comments reply Shaik Masthan commented Jan 3 reply Follow flag (*p++ = *q++) ((*p)++) = ((*q)++) With-in a sequence point, *p updated twitce. So, this should be a undefined behaviour. 1 1 replyShare DTYDHTB commented Jan 3 reply Follow flag @Shaik Masthan isn't *p updated only once (assignment) and p updated once (increament) in one sequence point, as ++ have higher precedence then derefrence operator 1 1 replyShare Shaik Masthan commented Jan 3 reply Follow flag Ohh... My mistake ! You are right. then output will be 2 and 3 without comma. 1 1 replyShare DTYDHTB commented Jan 3 reply Follow flag @Shaik Masthan thanks for your response 0 0 replyShare Please log in or register to add a comment.
1 1 vote *p++ = *q++ first copies the value from j to i, then both pointers move to the next element.The while condition checks the assigned value, not the next one.After each assignment, p already points to the next element, so printf("%d", *p) prints that next value.Assign 1 → p moves → prints 2Assign 2 → p moves → prints 3Assign 3 → condition fails → loop stopsOutput: 23 DTYDHTB answered Jan 3 DTYDHTB comment Share Follow See 1 comment 1 1 comment reply Mannat_Sharma commented Feb 18 reply Follow flag it will print 23 1 1 replyShare Please log in or register to add a comment.