A double subscripted array element incorrectly referenced as a[ x, y ] is actually evaluated as:
a. a[ x ][ y ] b. a[ y ] c. a[ x ] d. a[ 0 ]
please help
C++ for beginners?
Yes that is True.......
Compiler implements two-dimensional arrays similarly to how it implements one-dimensional arrays: as a pointer to the first byte in a large chunk of data. The only thing is, the compiler keeps track of how long each row is and you only have to keep track of how many columns there are (so you don't go off the end of the array). For example, if array is an m×n array of integers (m rows, n columns) and you request array_name[i][j], then the compiler returns the i×n + jth integer in the data chunk that array_name points to. As a result, array_name[i] is almost meaningless.
Setting a pointer-to-a-pointer equal to a double subscripted array yeilds a compiler error, and setting a pointer to a single subscripted array yeilds segfaults. Declaring the variables as arrays (and not pointers) results in more compiler errors.
Important
**********
expression1 [expression2] [expression3]...
Subscript expressions associate from left to right. The leftmost subscript expression, expression1[expression2], is evaluated first. The address that results from adding expression1 and expression2 forms a pointer expression; then expression3 is added to this pointer expression to form a new pointer expression, and so on until the last subscript expression has been added. The indirection operator (*) is applied after the last subscripted expression is evaluated, unless the final pointer value addresses an array type.
Expressions with multiple subscripts refer to elements of multidimensional arrays. A multidimensional array is an array whose elements are arrays. For example, the first element of a three-dimensional array is an array with two dimensions.
What happens is that the C++ compiler sets aside memory for the two dimensional array one row at a time. The memory cell after grBkEntry[0] [3] in memory is grBkEntry[ 1] [0].
hope this helps
Cheers:)
Reply:WE DONT ANSWER QUESTIONS FOR YOUR OWN EXAM / PAPER.. GO RESEARCH PLEASE.
Reply:nice legs
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment