C Operators & Type Conversion

Arithmetic, comparison, logical and casting.

✍️ 2 exercises in this lesson
  • Arithmetic: + - * / % ++ --
  • Assignment: = += -= *= /=
  • Comparison: == != > < >= <= (result is 1 for true, 0 for false)
  • Logical: && || !

Casting

Integer division drops the decimals: 7 / 2 is 3. Cast to get a decimal result: (float) 7 / 2 is 3.5.

Key Takeaways: C Operators & Type Conversion

Mastering C Operators & Type Conversion helps you write clean and reliable C code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

C Operators & Type Conversion Code Example

C
#include <stdio.h>

int main() {
    int a = 7, b = 2;
    printf("%d\n", a / b);
    printf("%.1f\n", (float) a / b);
    printf("%d\n", a % b);
    printf("%d\n", a > b && b > 0);

    int x = 5;
    x += 3;
    printf("%d\n", x++);
    printf("%d\n", x);
    return 0;
}
Output
3
3.5
1
1
8
9
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

C Operators & Type Conversion Practice Exercises

Check what you learned in “C Operators & Type Conversion”.

/ 2 solved
Fill in the blank

Cast to float so 7 / 2 gives 3.5.

float r =  7 / 2;
✓ Correct! Not quite. Try again.
Multiple choice

In C, what value does a true comparison produce?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services