Are the following two code blocks exactly the same and achieve the same thing?It displays the same thing when I run the program,but I would appreciate some rigorous explanation.
for(i=1;i<=10;i++)
{
printf("%d\n",i);
}
and
for(i=1;i<=10;printf("%d\n",i),i++);
The for
loop expects valid C statements as arguments,doesn't it? But even though I have verified on StackOverflow that statements like x+=4,y=x*2;
are safe as the comma acts as sequence points here, is the same truth for the statement printf("%d\n",i),i++)
passed as argument in the for
loop above?
And if yes, please bother to answer the minor question that arise from it:
Does the
comma
act as sequence points in a statement involving many comma separatedfunction calls as below:
printf("Enter number\n"),scanf("%d",&number),printf("You entered %d",number);