Assignment Doubt in c

0

Here's my code, why if there is change in the other variables, am I not just changing the row by the variable value? what reason for the others to change?

int a = 1, b = 2, c = 3, valor = 0;

valor = a;
printf("%d\n" , valor);

valor = b++;
printf("%d\n", valor);

valor = ++c;
printf("%d\n", valor);

valor += b;
printf("%d\n", valor);

valor *= c;
printf("%d\n", valor);
    
asked by anonymous 08.08.2018 / 01:36

2 answers

1

When doing b ++ or ++ b you are tweaking the variable b

It is different than making value + = b, in this case only the variable "value"

    
08.08.2018 / 01:39
4
  • Case 1:

    valor = a; assign a to variable valor ;

  • Case 2:

    valor = b++; is the same as the following sequence:

    valor = b;

    b = b + 1;

  • Case 3:

    valor = ++c; is the same as the following sequence:

    c = c + 1;

    valor = c;

  • Case 4:

    valor += b; is the same as the following sequence:

    valor = valor + b;

  • Case 5:

    valor *= c; is the same as the following sequence:

    valor = valor * c;

08.08.2018 / 02:40