Q:

Understanding double and integers

Absolute beginner programmer and wondered if you could help me understand some results and terms. I'm trying to follow the programs logic and how it works out certain values. The following case is an example to try and understand these concepts.
#include <stdio.h>
void main ()
{
    int inum = 11;
    double dnum = 2.56;

    double dec_result;
    int int_result;

    dec_result = inum / 4 + (3.0 * inum) / 5;
    printf("value in dec_result is %.2f\n", dec_result);

    dec_result = (double) inum / 4 + (3 * inum) / 5;
    printf("value in dec_result is %.2f\n", dec_result);

    int_result = (int) dnum * 10 + 1;
    printf("value in int_result is %d\n", int_result);

    int_result = (int) (dnum * 10 + 1);
    printf("value in int_result is %d\n", int_result);

}

I know the results as I've run it through Visual Basic. What I'm struggling to follow is how it works it out.
My workings:
inum and dnum I presume are 'names for values' and could be used interchangeably with say x or y. Same with int_result and dec_result.
First dec_result is 8.60
dec_result = inum / 4 + (3.0 * inum) / 5;
         11 (an integer) / 4 + (3.0 * 11) / 5
         11 (an integer) / 4 + (33.0) / 5

Then I'm a bit lost...  2.75 + 6.6?
Somehow, due to inum being an integer, value is truncated if written as fraction. But as remaining inum in the brackets is multiplied first then it becomes a decimal place number?
It's displayed as decimal places as specified by the placeholder and specified by data type double.
Second dec_result is 8.75
dec_result = (double) inum / 4 + ( 3 * inum) / 5;
       = as double is a cast operator you change inum from int to double, so therefore: 

       = (double) inum / 4 + (33) / 5;
Then   = inum/4 becomes 2.75 + 33/5

Why does the 33/5 bit become 6?
It's displayed as decimal places as specified by the placeholder and specified by data type double.
int_result = (int) dnum * 10 + 1;
       = cast operator alters dnum a double to integer so 2.56 becomes 2

       = 2 * 10 + 1
       = 20 + 1
       = 21

should be an integer as specified before the bracket and also %d placeholder means to provide the value as number with no decimal point.
int_result = (int) (dnum * 10 + 1);

I got:
           = (int) (2.56 * 10 + 1)
           = (int) (25.6 + 1)
           = (int) (26.6)
           = 26 
because the value should be an integer as specified before the bracket and also %d placeholder means to provide the value as number with no decimal point.
Is my logic correct?

A:

The C compiler will do integer arithmetic only if both operands are integers (integer / integer, integer + integer, etc.), otherwise it will do floating point arithmetic (double / integer, double + integer, etc.)
First result:
11 (an integer) / 4 + (33.0) / 5

The first part (11/4) is computed with integer arithmetic, so the answer is 2
The second part (33.0 / 5) is computed with floating point arithmetic, so the answer is 6.6 and the sum is 8.6
Second result:
(double) inum / 4 + (33) / 5;

"(double) inum / 4" is computed using floating point arithmetic, so the answer is 2.75.
"33 / 5" is computed using integer arithmetic, so the answer is 6, and the sum is 8.75
In the following:
int_result = (int) dnum * 10 + 1;

The variable dnum is first cast to an integer, so integer arithmetic is used: 2 * 10 + 1 == 21
And finally:
int_result = (int) (dnum * 10 + 1);

In this case, "dnum * 10 + 1" is computed first, which is done using floating point arithmetic: 2.56 * 10 + 1 == 26.6.  Then the cast - (int) - truncates to give 26.

