Basic C operation ++a

#include <stdio.h>

int main(void) {
int a,b;
printf("%d %d %d",++a,++a,++a);
return 0;

Output for this is 8 8 8

How it is coming :frowning:
please explain

seems after all incrementing operations on a the printf works .
tbh maximum no one here knows or care about the internal working of languages , for this kinda problems you have

1 Like

The statement with the printf is undefined behaviour. I personally wouldn’t bother puzzling out why it gives a particular output - I recommend just not doing these kind of things in the first place :slight_smile:

1 Like

I am giving you complete clarity. i think you are using turbo c, in c language when you use printf() function then the values assigns from right to left in variables and output will come from left to right. that’s why this is happening.
in your first statement you are increasing b=a++ the value is increased by 1 then a and b is 5.
after then in printf the values are passing from right to left the first ++a will increase by 1 then a become 6 after then 7 after then 8.
and now printf works for printing the values from left to right so it will give output 8 8 8.
you can use one post increment a++ in your program so you get much clarity on this.
and it also depend compiler by compiler. this thing is work on turbo c.
upvote my answer!!

1 Like