Re: declaration of variable in for loop
poornimamprabhu wrote:
> Hi there,
>
> suppose i have piece of code like
> main()
> {
> int i,j;
> for(i=0;i<10;i++){
> int k = i;
> printf("%d %p = *%d\n",i,&k,k);
> }
> }
>
>
> When i see the address of K its same in all iterations.That means K is
> only defined once at a time.
The compiler *is* allowed to place k in a different place each time, but,
why should it?
--
Army1987 (Replace "NOSPAM" with "email")
|