c malloc | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

c malloc

Why do you have to add +2 to the pointer. *(ptr + 2) = 50; /* assign 50 to third int */

27th Jan 2019, 5:38 PM
Ornelio Reiph
Ornelio Reiph - avatar
2 Answers
+ 3
According to the comment, 50 is assigned to the third int. The third int has the offset 2. ptr points to the first int, ptr + 1 to the second and ptr + 2 to the third one.
27th Jan 2019, 5:46 PM
Anna
Anna - avatar
+ 1
*(ptr + n) is equivalent to ptr[n] or n[ptr]
27th Jan 2019, 5:51 PM
Bebida Roja
Bebida Roja - avatar