Re: Array and Pointer Tutorial
- From: "Chad" <cdalten@xxxxxxxxx>
- Date: 11 May 2006 20:08:27 -0700
You have not followed the suggested practice of using sizeof *pointer
being assigned to. Your example should have been:
#include <stdlib.h>
int main(void) {
int array[5];
int *q = malloc(sizeof *q);
return 0;
}
Or, if you want array and q to always be the same type, you could have used:
#include <stdlib.h>
int main(void) {
int array[5], *q = malloc(sizeof *q);
return 0;
}
I really can't see why you would think of using sizeof some other object.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
I can't really put me pinpoint the exact part, but I know I'm missing
some kind of underlying concept when I see the construction:
int *q = malloc(sizeof *q);
Maybe when I'm scrubbing the dairy coolers at work tomorrow morning,
the exact part that is irking me will set in. Then I can come back and
ask the EXACT question about the construction.
Chad
.
- Follow-Ups:
- Re: Array and Pointer Tutorial
- From: Richard Heathfield
- Re: Array and Pointer Tutorial
- 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
- Prev by Date: Re: returning address of stack variable
- Next by Date: Re: Array and Pointer Tutorial
- Previous by thread: Re: Array and Pointer Tutorial
- Next by thread: Re: Array and Pointer Tutorial
- Index(es):
Relevant Pages
|