Connecting Tech Pros Worldwide Forums | Help | Site Map

float ** and float *p[]

vjnr83@gmail.com
Guest
 
Posts: n/a
#1: Dec 6 '06
Hi,

I have a doubt:

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

Thanks in advance,
Vijay


Roger
Guest
 
Posts: n/a
#2: Dec 6 '06

re: float ** and float *p[]


vjnr83@gmail.com wrote in news:1165388674.473059.286870
@n67g2000cwd.googlegroups.com:
Quote:
Hi,
>
I have a doubt:
Me too ;)
Quote:
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
Keith Thompson
Guest
 
Posts: n/a
#3: Dec 6 '06

re: float ** and float *p[]


vjnr83@gmail.com writes:
Quote:
I have a doubt:
In most dialects of English, "doubt" is not a synonym for "question".
Quote:
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) kst-u@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.
mark_bluemel@pobox.com
Guest
 
Posts: n/a
#4: Dec 6 '06

re: float ** and float *p[]



vjnr83@gmail.com wrot
Quote:
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.

CoL
Guest
 
Posts: n/a
#5: Dec 6 '06

re: float ** and float *p[]


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

vjnr83@gmail.com wrote:
Quote:
Hi,
>
I have a doubt:
>
what is the difference between float **p and float *p[10]?
>
Thanks in advance,
Vijay
santosh
Guest
 
Posts: n/a
#6: Dec 6 '06

re: float ** and float *p[]


CoL wrote:
Quote:
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)
Quote:
now---
b) for(i=0;i<n;i++)
p[i]=(float*)malloc(sizeof(float));
Again: p[i] = malloc(n * sizeof(float));
Quote:
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.

Default User
Guest
 
Posts: n/a
#7: Dec 6 '06

re: float ** and float *p[]


CoL wrote:
Quote:
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
pete
Guest
 
Posts: n/a
#8: Dec 7 '06

re: float ** and float *p[]


santosh wrote:
Quote:
>
CoL wrote:
Quote:
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);
Quote:
That can be better written as:
float **p = malloc(n * sizeof *p)
>
Quote:
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
Barry Schwarz
Guest
 
Posts: n/a
#9: Dec 7 '06

re: float ** and float *p[]


On 6 Dec 2006 03:18:09 -0800, "CoL" <apraghuvanshi@gmail.comwrote:
Quote:
>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.
Quote:
>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.
Quote:
>
>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.
Quote:
>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.
Quote:
>
>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.
Quote:
>
>Regards
>COL
>
>vjnr83@gmail.com wrote:
Quote:
>Hi,
>>
>I have a doubt:
>>
>what is the difference between float **p and float *p[10]?
>>
>Thanks in advance,
>Vijay

Remove del for email
Closed Thread