r/programminghelp • u/thegodfather444 • Feb 14 '24
C pointers in C
so i'm learning C right now and i have a question about the use of pointers in arithmetic.
so when i declare ptr1 and ptr2 as pointers, and then i write *ptr2=*(ptr2)+ptr1 it works fine.
but if i write *ptr2+=ptr1 which is almost the same as before i get an error. can someone help me understand the += because it seem the problem is there
1
Upvotes
View all comments
Show parent comment
2
u/Furry_69 Feb 14 '24
In your calculation,
ptr1is not dereferenced. Of course, adding a pointer to anintdoesn't make any sense, but internally they're both numbers, so the compiler will just add them anyways and emit a warning.