A linguagem C possui um mecanismo de conversão automática de tipos. Considere que o tipo char tenha 1 byte, o tipo int tenha 2 bytes e o tipo float...
A linguagem C possui um mecanismo de conversão automática de tipos. Considere que o tipo char tenha 1 byte, o tipo int tenha 2 bytes e o tipo float tenha 4 bytes e que o código ASCII da letra Y é 89, da letra b é 98 e da letra c é 99. Analise o programa C abaixo. int main () { int x; char ch; float f; ch=x= 300; printf ("x=%d ch=%d\n", x, ch); x=ch=f= 98.8999; printf ("f= %.4f ch=%c x=%d \n", f, ch, x); return 0; } A saída desse programa é:
x= 255 ch=0 f= 98.8999 ch= Y x=89 x= 300 ch=300 f= 98. 8999 ch= c x=99 x= 300 ch=300 f= 98.89 ch= b x=98 x= 256 ch=44 f= 0.8999 ch= Y x=98 x= 300 ch=44 f= 98.8999 ch= b x=98
A saída do programa é:
x= 255 ch=0
f= 98.8999 ch= Y x=89
x= 300 ch=300
f= 98.8999 ch= c x=99
x= 300 ch=300
f= 98.89 ch= b x=98
x= 256 ch=44
f= 0.8999 ch= Y x=98
x= 300 ch=44
f= 98.8999 ch= b x=98
Espero ter ajudado! Se tiver mais alguma dúvida, é só perguntar.
0
0
Faça como milhares de estudantes: teste grátis o Passei Direto
Compartilhar