1
I studied the iterative artifice for
and thought the same applied to the following example:
for(i = 0; i < 7; i++){Código}
However, when studying the pointer part with vectors, I came across the following example:
#include <stdio.h>
#include <stdio.h>
int main()
{
int vet[7]={0};
int i;
for(i=0;i<7;i++)
printf("%d ",*(vet+i)); //Mostrando todos os valores do vetor
printf("\n\n");
printf("%i \n\n",vet); //Mostrando o endereco de memoria do primeiro indice do vetor
for(i=0;i<7;i++)
printf("%i ",(vet+i)); //Mostrando todos os endereco de memoria do vetor
printf("\n\n");
*(vet+5)=1024; //Alterando o indice seis para 1024
for(i=0;i<7;i++)
printf("%d ",*(vet+i)); //Exibindo todos os indices do vetor
getchar();
}
Why didn’t the author of this code use the keys and the iteration device worked? In my compiler (Codeblocks), if you put the keys the program does not return the same as the previous one.
In reality your indentation is wrong. Only the first
printf
after thefor
is that runs in the loop. The other printf runs after the end of the loop. You use the block{}
when you want to execute more than one command inside the loop.– anonimo