7th Nov 2019, 5:56 AM
Preity
Preity - avatar
6 Respuestas
+ 2
For output 20 you must write *(ptr+1) You must increment the pointer to get the next value in the array but you cannot do that by increasing or decreasing the value pointed by the pointer.
7th Nov 2019, 6:04 AM
Avinesh
Avinesh - avatar
+ 2
Thanks all for explaining me this 👍
7th Nov 2019, 9:17 AM
Preity
Preity - avatar
+ 1
Ipang , ~ swim ~ can you explain this question why 20 10 is not answer and why warning is coming?
7th Nov 2019, 6:00 AM
Preity
Preity - avatar
+ 1
Preity Kit Delano Cat was right, the warning actually tells you already, that output is undefined (or unpredictable). Output will differ between compilers and internal implementation. Any attempt to modify a data as well as accessing the data in a single point of execution sequence may lead to undefined behaviour. If I understood it correctly.
7th Nov 2019, 8:01 AM
Ipang
0
You have an integer pointer pointing to the array. Always remember the array name consist of the base address of the array. So int* ptr = arr; means ptr now is pointing to the first value of the array. So in the printf statement we use the dereferencing operator to retrieve the value pointed by ptr. We know that is 10, and you should understand that *ptr++ will also give 10 since it is post incremented. If you would have wrote ++*ptr then it would result in 11.
7th Nov 2019, 6:01 AM
Avinesh
Avinesh - avatar