If you have ...
char * p;
then *p is a char, p is a pointer to a character.
If you have...
char ** p;
then **p is a character, *p is a pointer to a character, p is a pointer to a pointer to a character.
All parameters in C are passed by value. So if you want to pass in a var parameter, you need to pass in a pointer to the value to be referenced/modified. But if you want to be able to change where the pointer is pointing from within a function, you need ** (otherwise you just change what the pointer is pointing to).
Terry
Phil Middlemiss wrote:
Thankyou.What does the ** operator in C?Cheers,Phil.----- Original Message -----From: TerrySent: Monday, April 19, 2004 1:20 PMSubject: Re: [DUG] Converting some code from Creturn exits the function immediately. goto is like the pascal goto.
Terry
Phil Middlemiss wrote:
One more question: The original C source code uses gotos. Does a "return" statement in C mean just leave the routine, or does it also return back to the next statement after the goto? I would assume that it does not continue after a goto statement, but this code is so convoluted I can't be sure what it intended to do just by looking at the code.Phil. ----- Original Message ----- From: "Terry" <[EMAIL PROTECTED]> To: "NZ Borland Developers Group - Delphi List" <[EMAIL PROTECTED]> Sent: Monday, April 19, 2004 12:18 PM Subject: Re: [DUG] Converting some code from CPointers and arrays are essentially equivalent in c. And pointer arithmatic works like array indexation, so ... *(snorm+n) = *(snorm+n-1)*(float)(2*n-1)/(float)n; and snorm[n] = *(snorm+n-1)*(float)(2*n-1)/(float)n; and snorm[n] = snorm[n-1]*(float)(2*n-1)/(float)n; are all equivalent statements. A reason you may wish to use the pure pointer form is where you don't want to pass an array and index offset into a function, you can just point to an element. And p++ will increment the pointer to the next array element (probably the reason p is used rather than snorm directly). Terry Phil Middlemiss wrote:I'm converting some code from some ugly C. The code defines oneparticulararray, and a constant like this: static float snorm[169]; static float *p = snorm; and then later has an assignment: *snorm = 1.0; and then again later (n is an integer iterator): *(snorm+n) = *(snorm+n-1)*(float)(2*n-1)/(float)n; The question is this: It looks like the code is simply assigning valuestoan array, so why bother with the pointers? Elsewhere the code uses arrays normally (ie. indexing them with the square brackets) so that makes methinkmaybe this is doing something other than just putting values into thearray.Also, I'm assuming that the "p" variable is just a pointer into snorm? Can anyone make this clear for me? Cheers, Phil. _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi
_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
