Re: Array and Pointer Tutorial
- From: "Chad" <cdalten@xxxxxxxxx>
- Date: 12 May 2006 03:53:51 -0700
pete wrote:
Richard Heathfield wrote:
Chad said:
Richard Heathfield wrote:<snip>
<snip>
p = malloc(n * sizeof *p);
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
.
- References:
- Re: Array and Pointer Tutorial
- From: Richard Bos
- Re: Array and Pointer Tutorial
- From: Chad
- Re: Array and Pointer Tutorial
- From: Flash Gordon
- Re: Array and Pointer Tutorial
- From: Chad
- Re: Array and Pointer Tutorial
- From: Richard Heathfield
- Re: Array and Pointer Tutorial
- From: Chad
- Re: Array and Pointer Tutorial
- From: Richard Heathfield
- Re: Array and Pointer Tutorial
- From: pete
- Re: Array and Pointer Tutorial
- Prev by Date: Re: Array and Pointer Tutorial
- Next by Date: Re: returning address of stack variable
- Previous by thread: Re: Array and Pointer Tutorial
- Next by thread: Re: Array and Pointer Tutorial
- Index(es):
Relevant Pages
|