As everyone knows this
is more efficient than thisCode:atype array[4] = {1, 2, 3, 4}; atype *p = array; for (int i = 0; i < 4; i++) { OperateOn(*p); p++; }
(except for those of you who don't know, dereferencing an array can amount to a multiplication operation and an addition operation, while the first solution just does an increment)Code:atype array[4] = {1, 2, 3, 4}; for (int i = 0; i < 4; i++) { OperateOn(array[i]); }
But what if you have
how do you go about iterating through that without using the square brackets? I triedCode:atype array[4][4] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16} };
But my first dereference of arrayx won me a seg fault. And arrayy was a sober-looking 0x7fffffffdb90 while arrayx was 0x200000001. No points for guessing where the "2" and the "1" of that come from. I just don't see how.Code:const atype **arrayy = (const atype **)array; const atype *arrayx = *array;



LinkBack URL
About LinkBacks




