470,641 Members | 2,412 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

float ** and float *p[]

Hi,

I have a doubt:

what is the difference between float **p and float *p[10]?

Thanks in advance,
Vijay

Dec 6 '06 #1
8 5091
vj****@gmail.com wrote in news:1165388674.473059.286870
@n67g2000cwd.googlegroups.com:
Hi,

I have a doubt:
Me too ;)
what is the difference between float **p and float *p[10]?
The first is a pointer to a pointer. The second is an array of 10
pointers.

Now, what do you really want to know?

-R
Dec 6 '06 #2
vj****@gmail.com writes:
I have a doubt:
In most dialects of English, "doubt" is not a synonym for "question".
what is the difference between float **p and float *p[10]?
Read section 6 of the comp.lang.c FAQ, <http://c-faq.com/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 6 '06 #3

vj****@gmail.com wrot
what is the difference between float **p and float *p[10]?
Lots...

The first specifies that the variable "p" is a pointer,which when
resolved would point in turn to a pointer, which would in turn point to
a data item of "float" type. It is your job to make sure both the
second pointer and the float type exist...

The second specifies that "p" is an array of ten items each of which is
a pointer to a float data type .

I suggest you go to the FAQ and read http://c-faq.com/aryptr/index.html
and the pages pointed to from it.

Dec 6 '06 #4
CoL
Hi ,
float **p is moreover a generic form of the later one float *p[].
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 .

An example of float **p----
a) float **p=(float**) malloc(sizeof(*float)*n); //where n is some size
known at run time
now---
b) for(i=0;i<n;i++)
p[i]=(float*)malloc(sizeof(float));
Now you can store valures in p[i]s.

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.

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
Dec 6 '06 #5
CoL wrote:
Hi ,
float **p is moreover a generic form of the later one float *p[].
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 .

An example of float **p----
a) float **p=(float**) malloc(sizeof(*float)*n); //where n is some size
known at run time
That can be better written as:
float **p = malloc(n * sizeof *p)
now---
b) for(i=0;i<n;i++)
p[i]=(float*)malloc(sizeof(float));
Again: p[i] = malloc(n * sizeof(float));
Now you can store valures in p[i]s.

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.
An important difference is that in float **p, p can be modifiable while
in float *p[], p is non-modifiable.

Dec 6 '06 #6
CoL wrote:
Hi ,
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>

Brian
Dec 6 '06 #7
santosh wrote:
>
CoL wrote:
Hi ,
float **p is moreover a generic form of the later one float *p[].
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 .

An example of float **p----
a) float **p=(float**) malloc(sizeof(*float)*n);
That can be better written as:
float **p = malloc(n * sizeof *p)
now---
b) for(i=0;i<n;i++)
p[i]=(float*)malloc(sizeof(float));

Again: p[i] = malloc(n * sizeof(float));
ITYM p[i] = malloc(k * sizeof *p[i]);

There's not really any information given
to guess how many floats can be accessed through p[i].

--
pete
Dec 7 '06 #8
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
Dec 7 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Pat | last post: by
14 posts views Thread by Glen Able | last post: by
16 posts views Thread by Gerald Lafreniere | last post: by
6 posts views Thread by Dave win | last post: by
9 posts views Thread by Sisyphus | last post: by
11 posts views Thread by Marc Pelletier | last post: by
20 posts views Thread by ehabaziz2001 | last post: by
13 posts views Thread by Shirsoft | last post: by
???
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.