+ 2

Why the output is 7.How it is executed???

check this code https://code.sololearn.com/cfvk9hVaBQJS/?ref=app

15th Jun 2018, 10:27 AM
Dhanaraj S
Dhanaraj S - avatar
3 Answers
+ 1
It is called post incrementing. First assign the value to q and then increments it.
15th Jun 2018, 10:58 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
int i = 7 will create int variable with value of 7 and *q is pointer variable. doing q = &i; will assign *q with address of i. now on printf("%d", *q++); will print the value of at address stored in q. using q++ will print the value first and then it will increase the value. so the output is 7.
15th Jun 2018, 10:32 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
It shows 7 because '++' after the variable executes after, if you want to execute it before you should use '++' before the variable.
15th Jun 2018, 10:32 AM
Alexandru Turculet
Alexandru Turculet - avatar