Answer the question
In order to leave comments, you need to log in
How does C pointer arithmetic work?
At the exam in programming (C language) there was such a question
"If c is an array of char, then what is the difference (c + 3) - c (in bytes)?".
The correct answer is 3.
Please explain how 3 is obtained?
Answer the question
In order to leave comments, you need to log in
When you subtract pointers, the result is the number of elements of the specified type between those pointers. In your case, 3 char seems to assume that sizeof(char) == 1. In general, this is not the case, the correct answer is 3*sizeof(char).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question