#include #include troca_por_referencia(float *v1, float *v2) { float temp; temp=*v1; *v1=*v2; *v2=temp; printf ("Troca por Referencia:\n"); printf ("DENTRO: V1=%.4f - V2=%.4f\n",*v1,*v2); } troca_por_valor(float v1, float v2) { float temp; temp=v1; v1=v2; v2=temp; printf ("Troca por Valor:\n"); printf ("DENTRO: V1=%.4f - V2=%.4f\n",v1,v2); } int main() { float a,b; printf(">> Teste de Troca de Valores <<\n"); printf(">> Passagem de Parametros <<\n"); printf("\n"); printf("Digite o valor float A: "); scanf ("%f",&a); printf("Digite o valor float B: "); scanf ("%f",&b); printf("\n"); printf("Passagem de parametros por Valor\n"); printf("ANTES : A=%.4f - B=%.4f\n",a,b); troca_por_valor(a,b); printf("DEPOIS: A=%.4f - B=%.4f\n",a,b); printf("NAO teve efeito a troca com passagem de parametro por valor!\n"); printf("\n"); system("pause"); printf("\n"); printf("Passagem de parametros por Referencia\n"); printf("ANTES : A=%.4f - B=%.4f\n",a,b); troca_por_referencia(&a,&b); printf("DEPOIS: A=%.4f - B=%.4f\n",a,b); printf("TEVE efeito a troca com passagem de parametro por valor!\n"); printf("TROCOU os valores pois passou o endereco da variavel!\n"); printf("\n"); system("pause"); printf("\n"); printf("FIM!\n"); system("pause"); return 0; }