Are arrays in C++ same as C? -


does c++ compiler treat arrays same way in c?

e.g

in c,

  • an array access using subscript operator interpreted pointer.
  • in function argument, array declarations treated pointer start of element.

yes , no. arrays work same in both languages part (c99 supports variable-length arrays, while c++ doesn't, , there may few other subtle differnces well).

however, you're saying isn't exactly true either. compiler doesn't treat array access pointer, not in c. array access can more efficient in cases, because compiler has better information on aliasing available in array case. in both c , c++, plain pointer access means compiler has assume may alias other compatible type. if compiler treated pointer dereference, optimization opportunity lost.

edit
pointed out in comment, language standard does define array subscripting in terms of pointer arithmetics/dereferencing. of course, actual compilers make use of additional information pointer array, they're not treated exactly pointers, considered optimization beyond standard mandates.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -