Created
August 29, 2010 06:05
-
-
Save kaldas/556020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Uma otima demonstracao de ponteiros em C | |
* http://einstein.drexel.edu/courses/Comp_Phys/General/C_basics/#pointers */ | |
#include <stdio.h> | |
int main() | |
{ | |
float x, y; /* x e y sao do tipo float */ | |
float *fp, *fp2; /* fp e fp2 sao ponteiros para float */ | |
x = 6.5; /* x agora contem o valor 6.5 */ | |
/* imprime o conteudo e endereco de x */ | |
printf("Valor de x agora eh %f, endereco de x %ld\n", x, &x); | |
fp = &x; /* fp agora aponta para o endereco de x */ | |
/* imprime o conteudo de fp */ | |
printf("Valor no endereco de memoria de fp eh %f\n", *fp); | |
/* muda o conteudo do endereco de memoria */ | |
*fp = 9.2; | |
printf("Novo valor de x eh %f = %f \n", *fp, x); | |
/* faz a arimetica */ | |
*fp = *fp + 1.5; | |
printf("Valor final de x eh %f = %f \n", *fp, x); | |
/* transfere os valores */ | |
y = *fp; | |
fp2 = fp; | |
printf("Valores transferidos para y = %f e para fp2 = %f \n", y, *fp2); | |
} | |
//traduzido por rcaldasmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment