Re: Array and Pointer Tutorial




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

.



Relevant Pages

  • Re: C99 exact width integers usage - informal survey
    ... so you can write perfectly portable code (assuming ANSI ... yes and no on the portability issue. ... types int and unsigned int. ... That's why the exact sized int types are not required in C99 unless ...
    (comp.arch.embedded)
  • Re: Matrix decomposition, time complexity doubt?
    ... of a correct algebraic formulae instead of an iterative approximation? ... 10^6 exact values would seem to be a curious sort of problem ... Int 0_N Int 0_N kdx dt = a ... to solve this type of Integral equation, ...
    (sci.math.num-analysis)
  • Re: bits for floating value and converting
    ... The exact value that you got ... as an int. ... the length of a float ... That's a Fortran question rather than a C question. ...
    (comp.lang.c)
  • Re: Matrix decomposition, time complexity doubt?
    ... By exact do you mean that the result is a many digit rational number ... of a correct algebraic formulae instead of an iterative approximation? ... Int 0_N Int 0_N kdx dt = a ... to solve this type of Integral equation, ...
    (sci.math.num-analysis)
  • Re: Play Wales Bin
    ... what we do is we use an int to ensure we have that exact number in ... and then we do some evil: we tell the compiler to take the ...
    (uk.games.video.misc)