Ir ao conteúdo
  • Cadastre-se

C Exercicio na Linguagem C


Sun__

Posts recomendados

Eae boa noite, apenas quero saber se o exercício de C que fiz está correto, e se tiver erros também gostaria de saber quais são, obrigado, segue o exercício:

 

 

Exercise 2.17First, fully parenthesize the following expressions according to the precedence and associativity rules. Then, replacing the variables and constants with the appropriate type names, show how the type of the expression is derived by replacing the highest precedence expressions with its resulting type.

The variables are:

char c; int i; unsigned u; float f;

For example: i = u+1; parenthesizes as (i = (u + 1));

The types are

(int = (unsigned + int));

then

(int = (unsigned)); /* usual arithmetic conversions */

then

(int); /* assignment */

a) c = u * f + 2.6L;

b) u += --f / u % 3;

c) i <<= u * - ++f;

d) u = i + 3 + 4 + 3.1;

e) u = 3.1 + i + 3 + 4;

f) c = (i << - --f) & 0xf;

 

 

 

-> Minha Resposta: 

 

a) c = u * f + 2.6L;
(c = ((u * f) + 2.6L));
(char = ((unsigned * float) + long_float));
(char = ((float) + long_float));
(char = (long_float));
(long_float);

 

b) u += --f / u % 3;
(u += (--f / u) % 3);
(unsigned += ((--float) / unsigned) % int);
(unsigned += (float) % int));
(unsigned += (int));
(int);

 

c) i <<= u * - ++f;
(i <<= u * (- ++f));
(int <<= unsigned * (- ++float));
(int <<= (float));
(int <<= (float));
(float);

 

d) u = i + 3 + 4 + 3.1;
(u = (((i + 3) + 4) + 3.1));
(unsigned = (((int + int) + int) + float));
(unsigned = (((int) + int) + float));
(unsigned = (int) + float));
(unsigned = (float));
(float);

 

e) u = 3.1 + i + 3 + 4;
(u = (((3.1 + i) + 3) + 4));
(unsigned = (((float + int) + int) + int));
(unsigned = (((float) + int) + int));
(unsigned = ((int) + int));
(unsigned = (int));
(int);

 

f) c = (i << - --f) & 0xf;
(c = ((i << (- --f)) & 0xf));
(char = ((int << (- --float)) & hex));
(char = ((- --float) & hex));
(char = (hex));
(char);

 

  • Amei 1
Link para o comentário
Compartilhar em outros sites

@Sun__    Olá  , seria bom se você tivesse traduzido esse texto para português ,  pois aqui é esse o idioma ,    e  na linguagemesses parenteses adicionados não fariam diferença ,  pois ali a ordem de precedência  seria aquela mesma que já esta na questão .    certo ! 

Link para o comentário
Compartilhar em outros sites

Em 03/08/2020 às 21:02, Sun__ disse:

a) c = u * f + 2.6L;
(c = ((u * f) + 2.6L));
(char = ((unsigned * float) + long_float));
(char = ((float) + long_float));
(char = (long_float));
(long_float);

Termina com (char) e mais nada.

 

Em 03/08/2020 às 21:02, Sun__ disse:

b) u += --f / u % 3;
(u += (--f / u) % 3);
(unsigned += ((--float) / unsigned) % int);
(unsigned += (float) % int));
(unsigned += (int));
(int);

"Houve um equivoco", regra nas especificações que não pode envolver número flutuante em mod (%).

 

Em 03/08/2020 às 21:02, Sun__ disse:

c) i <<= u * - ++f;
(i <<= u * (- ++f));
(int <<= unsigned * (- ++float));
(int <<= (float));
(int <<= (float));
(float);

Não pode terminar em (float), e a regra do mod aplica-se também ao operador de binário. 

 

Parei!

  • Curtir 3
Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!