Skip to content

Instantly share code, notes, and snippets.

@renatoargh
Created July 26, 2012 23:29
Show Gist options
  • Select an option

  • Save renatoargh/3185230 to your computer and use it in GitHub Desktop.

Select an option

Save renatoargh/3185230 to your computer and use it in GitHub Desktop.
void alterarValor(int* x){ //repare nesta linha, recebemos um endereço
*x = *x + 2;
}
int main(){
int x = 4;//x armazenada em `stack`
int *endereco_de_x = &x;
printf("x está armazenada em %p \n\n", endereco_de_x);
//x está armazenada em 0x7fff69032c24
printf("Valor inicial de x: %i \n", x);
alterarValor(endereco_de_x); //aqui passamos o endereço
printf("Valor de x: %i >>> alterado com sucesso!!!", x);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment