in Programming in C
324 views
1 vote
1 vote

what is the output?

in Programming in C
by
324 views

1 Answer

2 votes
2 votes
Best answer
In this, *++ptr will increment the pointer first and then assign the value pointed by the pointer to the variable. *ptr++ will first assign the value pointed by the pointer to the variable.

So,

a=*++ptr; will cause the pointer point to 'a' in "MadeEasy" first and then assign the value 'a' to variable a

b=*ptr++ will cause first assign value 'a' to the variable b and then shift the pointer to d

similarly, in second iteration,

a=*++ptr; will cause a to store e (as pointer is shifted first)

b=*ptr++  will cause b to store e (e is assigned and pointer now points to E)

and in last iteration, a and b both will contain the character 'a'.

Hence a a will be printed
selected by

1 comment

Thanks @gauravkc

0
0

Related questions

0 votes
0 votes
1 answer
1
himgta asked in Programming in C Sep 12, 2018
390 views
himgta asked in Programming in C Sep 12, 2018
by himgta
390 views
0 votes
0 votes
1 answer
2
himgta asked in Programming in C Sep 6, 2018
447 views
himgta asked in Programming in C Sep 6, 2018
by himgta
447 views