Re: declaration of variable in for loop



Mark L Pappin wrote:
jacob navia <jacob@xxxxxxxxxx> writes:

main()
{
int i,j, *pint;
for(i=0;i<10;i++){
int k = i;
printf("%d %p = *%d\n",i,&k,k);
pint=&i;
}
*pint = 789; // Accessing illegal storage

What's illegal about it?

If the last statement inside the loop body had instead been
pint=&k;
then you might have a point.

mlp

Yes, I mistyped the name of the variable

Thanks


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
.



Relevant Pages

  • Re: new order doubt
    ... Warning test2.c: 8 no type specified. ... Defaulting to int ... Even Microsoft has problems with this obscure rules. ... jacob at jacob point remcomp point fr ...
    (comp.lang.c)
  • Re: strtod strange behaviour
    ... int main ... char *p = NULL; ... printf("%s converted is %g\n", szValue, a); ... jacob at jacob point remcomp point fr ...
    (comp.lang.c)
  • Re: size_t problems
    ... strlen's result to an int is clearly wrong; strlen yields size_t, ... but that does not make him a troll. ... Now, I sometimes disagree with Jacob, but I think he makes an honest ...
    (comp.lang.c)
  • Re: similar Perl data structure?
    ... In Perl, I just read them into an array, ... int EXPORT fggets ... error code if an error happened. ... jacob at jacob point remcomp point fr ...
    (comp.lang.c)
  • Re: which tutorial to use?
    ... If the compiler is sensible it will keep int 32 bits, ... The problem is that if you put int to 64 bits you have a BLOAT ... of the size of all structures, and your program slows down ... jacob at jacob point remcomp point fr ...
    (comp.lang.c)