
November 12th, 2012, 03:50 AM
|
|
|
Quote: | Originally Posted by varshc1
Code:
#include<stdio.h>
void main()
{
int i;
i=3;
printf("%d%d",i,i++);
}
output of this is displayed as 43 y???  |
Because using and updating an object without an intervening sequence point is undefined behaviour.
Basically an object is a variable.
Very basically a sequence point is the semicolon at the end of a statement.
In your printf("%d%d", i, i++) statement, you use the value of i and update it in the same expression originating UB.
You never ever want to write programs that contain UB!
So ... don't do that. Write your program as one of the following alternate options:
Code:
#include<stdio.h>
int main(void)
{
int i, j;
i = 3;
j = i++;
printf("%d%d\n", i, j);
}
Code:
#include<stdio.h>
int main(void)
{
int i;
i = 3;
printf("%d%d\n", i, i);
i++;
}
|