c - What is the length of an array? -


what length mean in sentence: "each array passed function along “length” of array."

does mean size of array?

in c, because have pointer array, doesn't mean know length (how many entries has). somehow must know avoid array indexing errors.

there small number of ways this:

  • agree on array length. code knows arrays have length, e.g., 17. considered bad practice, people arrays problem-domain specific such translation matrices 3d graphics, tend have 4 rows.
  • document array length constant declaration or macro definition, , use symbol control loops accessing array.
  • implicitly associate well-known variable containing runtime array size array. program consults variable when needs know array size.
  • pass pointer array, , length known by caller callee. callee knows length, , can in turn pass whoever callee calls.
  • package array , length in struct, , pass pointer struct. callee can consult struct determine array size.

this discussion little confusing c language, because tend in general conversation treat array length , array size being synonyms. in c, "size" has specific meaning; number of storage units occupied entity. computed array length, , programs pass "size" rather length. imho should pass array lengths functions manipulate arrays indexing them, length more abstract , easier understand.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -