I am very familiar with STL vector (and other container) performance guarantees, however I can’t seem to find anything concrete about plain arrays.
Are pointer arithmetic and [] methods constant or linear time?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are constant time. (Same as
vector.)When you say
a[b], it becomes*(a + b). Both (pointer arithmetic) addition and dereferencing are constant time.When adding an integer to a pointer, it moves that many elements over:
Every operation in there is constant time.