On 6 Dec 2006 03:18:09 -0800, "CoL" <ap***********@gmail.comwrote:
>Hi ,
float **p is moreover a generic form of the later one float *p[].
Only under a very limited set of circumstances. You have totally
ignored several significant distinctions:
One is an aggregate and the other is a scalar.
One is a modifiable lvalue and the other is not.
The sizeof operator will usually return radically different
results when applied to each.
>The second one float *p[] which is array of 10 pointers to float -- you
generally use
when you are sure about the SIIZE of your requirement.
And the first float **p which is obviously pointer ->pointer
essentially same as first --- in a more flexible form .
Not even close. Think about the situation where you want a function
to modify a float* that resides in the calling function.
>
An example of float **p----
a) float **p=(float**) malloc(sizeof(*float)*n); //where n is some size
known at run time
Don't cast the return from malloc.
>now---
b) for(i=0;i<n;i++)
p[i]=(float*)malloc(sizeof(float));
Now you can store valures in p[i]s.
A singularly uninstructive example. If each p[i] was intended to
point to a single float then a float** is completely unnecessary.
>
Step (a) is not required in the later case float *p[10] as you already
defined its size to 10.
Just second step (b) and move ahead.
Equally uninstructive.
And while you are at it, please don't top post.
>
Regards
COL
vj****@gmail.com wrote:
>Hi,
I have a doubt:
what is the difference between float **p and float *p[10]?
Thanks in advance,
Vijay
Remove del for email