Re: Array and Pointer Tutorial



pete wrote:
Richard Heathfield wrote:

Chad said:

Richard Heathfield wrote:

<snip>

p = malloc(n * sizeof *p);

<snip>

Are you saying that the construction
char *p = malloc(sizeof *p);

He said "for n objects of type T"

would allocate enough space to hold the string ""Hello, world!"

Which letter of 'n' were you struggling with?

I generally consider three different malloc situations:

1 "n objects of type T"
T *p = malloc(n * sizeof *p);
T *p = malloc(sizeof *p); /* when n == 1 */

2 string
char *p = malloc(length + 1);
char *p = malloc(sizeof "string_literal");

3 pointer to type void
void *p = malloc(sizeof object_identifier);

p = malloc(sizeof car);
*(struct vehicle *)p = car;

--
pete

The statement "for n objects of type T" didn't immediately register in
my snoodle. Anyhow after sleeping for 3 hours and re-reading the posts,
the entire thread makes sense.

Chad

.



Relevant Pages

  • Re: If Pete Best Had Remained in the Group....
    ... RMB..which mean that if all I've been saying is bullshit then why ... I'm more than willing to stipulate that Roag believes your theory. ... Pete or his mom may have implanted into his brain that ... I fully expect that if Danny's theory were true, some "dog" with inside ...
    (rec.music.beatles)
  • Re: If Pete Best Had Remained in the Group....
    ... Right OK...so you now concur that Roag Best signed "To the Walrus" as ... Pete for that matter) posted in and told us that what I'm saying is ... They wanted Ringo in and they finally got him. ...
    (rec.music.beatles)
  • Re: If Pete Best Had Remained in the Group....
    ... Pete for that matter) posted in and told us that what I'm saying is ... The fact that Pete has never said this was the reason for his leaving, ... of them all agreeing to keep it quiet. ...
    (rec.music.beatles)
  • Re: Array and Pointer Tutorial
    ... pete wrote: ... Are you saying that the construction ... Which letter of 'n' were you struggling with? ...
    (comp.lang.c)
  • Re: Mike doesnt understand this group [Was: Linux/Windows? Dual Boot?]
    ... > Are you saying that you identify with your computer hardware?! ... Are you saying you identify with the Fedora/Debian I loaded on my computer? ... > walking into your living room and explaining that the living room is ... I thin you are starting to see it, Pete, but still unwilling to admit ...
    (alt.os.linux)