For the below program
#include<stdio.h>
int main()
{
char str1[] = "India";
char str2[] = "BIX";
char *s1 = str1, *s2=str2;
while(*s1++ = *s2++)
printf("%s", str1);
printf("\n");
return 0;
}
How the condition in while loops gets evaluated? I can see the similar post in stack overflow here, but they didn't give explanation how * operator has greater precedence than postfix operator.But actually, postfix operator has greater precedence than * (Derefernce) operator. Precedence table for our reference here
Please explain how this code prints below output
BndiaBIdiaBIXia
Operator precedence and order of execution is not necessarily the same thing.
*s1++ = *s2++
Is evaluated by the compiler as follows:
char
at s1 is set to the char
's value at s2Even if ++
is of higher precedence as *
, it is still done last. Precedence here just means the post-increment operation has to be done to the pointer, and not to the value at the pointer