O que será impresso com a execução do programa em C a seguir?
#include
main() {
int x = 6, y = 7, z = 8;
if ((x < y) && (y > z)) {
x = y++;
y = ++z;
z = x--;
x = --z;
}
else if ((x > z) || (z > y)) {
x = y + z;
y = z + x;
z = x + y;
}
else {
x *= y;
y *= z;
z *= x;
}
printf(“X=%d Y=%d Z=%d”,x,y,z);
getch();
}
Respostas
Vai ser impresso 6 erros.
O primeiro erro que podemos observar está contido na sentença "if ((x < y) && (y > z))", nunca o numero 7 será maior que 8, logo tornando a sentença falsa.
Temos também a declaração do main, tem que ser int main().
Os erros imprimidos são:
main.c:10:9: error: #include expects "FILENAME" or
#include
^
main.c:11:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
main() {
^~~~
main.c: In function ‘main’:
main.c:31:1: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
printf(“X=%d Y=%d Z=%d”,x,y,z);
^~~~~~
main.c:31:1: warning: incompatible implicit declaration of built-in function ‘printf’
main.c:31:1: note: include ‘’ or provide a declaration of ‘printf’
main.c:31:8: fatal error: stray ‘\342’ in program
printf(“X=%d Y=%d Z=%d”,x,y,z);
^
main.c:31:9: error: stray ‘\200’ in program
printf(“X=%d Y=%d Z=%d”,x,y,z);
^
main.c:31:10: error: stray ‘\234’ in program
printf(“X=%d Y=%d Z=%d”,x,y,z);
^
main.c:31:11: error: ‘X’ undeclared (first use in this function)
printf(“X=%d Y=%d Z=%d”,x,y,z);
^
main.c:31:11: note: each undeclared identifier is reported only once for each function it appears in
main.c:31:13: error: expected expression before ‘%’ token
printf(“X=%d Y=%d Z=%d”,x,y,z);
^
main.c:31:25: error: stray ‘\342’ in program
printf(“X=%d Y=%d Z=%d”,x,y,z);
^
main.c:31:26: error: stray ‘\200’ in program
printf(“X=%d Y=%d Z=%d”,x,y,z);
^
main.c:31:27: error: stray ‘\235’ in program
Resposta:
Explicação: A 16