Click here to Skip to main content
15,845,742 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
QuestionPointers and brain drain Pin
honey the codewitch18-Jun-22 2:47
mvahoney the codewitch18-Jun-22 2:47 
AnswerRe: Pointers and brain drain Pin
Amarnath S18-Jun-22 2:52
professionalAmarnath S18-Jun-22 2:52 
GeneralRe: Pointers and brain drain Pin
honey the codewitch18-Jun-22 2:58
mvahoney the codewitch18-Jun-22 2:58 
GeneralRe: Pointers and brain drain Pin
harold aptroot18-Jun-22 3:38
harold aptroot18-Jun-22 3:38 
AnswerRe: Pointers and brain drain Pin
Richard MacCutchan18-Jun-22 3:41
mveRichard MacCutchan18-Jun-22 3:41 
AnswerRe: Pointers and brain drain Pin
Greg Utas18-Jun-22 3:51
professionalGreg Utas18-Jun-22 3:51 
AnswerRe: Pointers and brain drain Pin
David O'Neil18-Jun-22 4:24
professionalDavid O'Neil18-Jun-22 4:24 
GeneralRe: Pointers and brain drain Pin
Mircea Neacsu18-Jun-22 6:04
Mircea Neacsu18-Jun-22 6:04 
Wonderful idea! You can combine the 2D array with double indirection. A very good example is in "Numerical Recipes in C".

Quote:
There is a subtle near-ambiguity in the C syntax for two-dimensional array
references. Let us elucidate it, and then turn it to our advantage. Consider the
array reference to a (say) float value a[i][j], where i and j are expressions
that evaluate to type int. A C compiler will emit quite different machine code for
this reference, depending on how the identifier a has been declared. If a has been
declared as a fixed-size array, e.g., float a[5][9], then the machine code is: “to
the address a add 9 times i, then add j, return the value thus addressed.” Notice that
the constant 9 needs to be known in order to effect the calculation, and an integer
multiplication is required (see Figure 1.2.1).
Suppose, on the other hand, that a has been declared by float **a. Then
the machine code for a[i][j] is: “to the address of a add i, take the value thus
addressed as a new address, add j to it, return the value addressed by this new
address.” Notice that the underlying size of a[][] does not enter this calculation
at all, and that there is no multiplication; an additional indirection replaces it. We
thus have, in general, a faster and more versatile scheme than the previous one. The
price that we pay is the storage requirement for one array of pointers (to the rows
of a[][]), and the slight inconvenience of remembering to initialize those pointers
when we declare an array.
Here is our bottom line: We avoid the fixed-size two-dimensional arrays of C as
being unsuitable data structures for representing matrices in scientific computing. We
adopt instead the convention “pointer to array of pointers,” with the array elements
pointing to the first element in the rows of each matrix.

("Numerical Receipes in C: The art of Scientific Computing" pag. 20)
Mircea

AnswerRe: Pointers and brain drain Pin
Gerry Schmitz18-Jun-22 5:32
mveGerry Schmitz18-Jun-22 5:32 
AnswerRe: Pointers and brain drain Pin
jmaida18-Jun-22 5:57
jmaida18-Jun-22 5:57 
AnswerRe: Pointers and brain drain Pin
Greg Utas18-Jun-22 5:57
professionalGreg Utas18-Jun-22 5:57 
QuestionRe: Pointers and brain drain Pin
Eddy Vluggen18-Jun-22 12:30
professionalEddy Vluggen18-Jun-22 12:30 
AnswerRe: Pointers and brain drain Pin
honey the codewitch18-Jun-22 12:35
mvahoney the codewitch18-Jun-22 12:35 
GeneralRe: Pointers and brain drain Pin
Eddy Vluggen18-Jun-22 13:06
professionalEddy Vluggen18-Jun-22 13:06 
GeneralRe: Pointers and brain drain Pin
honey the codewitch18-Jun-22 13:10
mvahoney the codewitch18-Jun-22 13:10 
GeneralRe: Pointers and brain drain Pin
Eddy Vluggen18-Jun-22 13:33
professionalEddy Vluggen18-Jun-22 13:33 
GeneralRe: Pointers and brain drain Pin
Greg Utas18-Jun-22 13:56
professionalGreg Utas18-Jun-22 13:56 
GeneralRe: Pointers and brain drain Pin
honey the codewitch18-Jun-22 18:03
mvahoney the codewitch18-Jun-22 18:03 
GeneralRe: Pointers and brain drain Pin
jmaida18-Jun-22 19:05
jmaida18-Jun-22 19:05 
GeneralRe: Pointers and brain drain Pin
jmaida18-Jun-22 19:12
jmaida18-Jun-22 19:12 
GeneralRe: Pointers and brain drain Pin
honey the codewitch18-Jun-22 20:09
mvahoney the codewitch18-Jun-22 20:09 
AnswerRe: Pointers and brain drain Pin
jmaida18-Jun-22 12:38
jmaida18-Jun-22 12:38 
QuestionRe: Pointers and brain drain Pin
Eddy Vluggen18-Jun-22 13:28
professionalEddy Vluggen18-Jun-22 13:28 
AnswerRe: Pointers and brain drain Pin
jmaida18-Jun-22 14:37
jmaida18-Jun-22 14:37 
QuestionRe: Pointers and brain drain Pin
Eddy Vluggen18-Jun-22 15:39
professionalEddy Vluggen18-Jun-22 15:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.