- C Programming Tutorial
- C - Home
- Basics of C
- C - Introduction
- C - Features
- C - Basics
- C - History
- C - Structure of C Program
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Tokens
- C - Keywords
- C - Identifiers
- C - User Input
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Integer Promotions
- C - Type Conversion
- C - Type Casting
- C - Booleans
- Constants and Literals in C
- C - Constants
- C - Literals
- C - Escape sequences
- C - Format Specifiers
- Operators in C
- C - Operators
- C - Arithmetic Operators
- C - Relational Operators
- C - Logical Operators
- C - Bitwise Operators
- C - Assignment Operators
- C - Unary Operators
- C - Increment and Decrement Operators
- C - Ternary Operator
- C - sizeof Operator
- C - Operator Precedence
- C - Misc Operators
- Decision Making in C
- C - Decision Making
- C - if statement
- C - if...else statement
- C - nested if statements
- C - switch statement
- C - nested switch statements
- Loops in C
- C - Loops
- C - While loop
- C - For loop
- C - Do...while loop
- C - Nested loop
- C - Infinite loop
- C - Break Statement
- C - Continue Statement
- C - goto Statement
- Functions in C
- C - Functions
- C - Main Function
- C - Function call by Value
- C - Function call by reference
- C - Nested Functions
- C - Variadic Functions
- C - User-Defined Functions
- C - Callback Function
- C - Return Statement
- C - Recursion
- Scope Rules in C
- C - Scope Rules
- C - Static Variables
- C - Global Variables
- Arrays in C
- C - Arrays
- C - Properties of Array
- C - Multi-Dimensional Arrays
- C - Passing Arrays to Function
- C - Return Array from Function
- C - Variable Length Arrays
- Pointers in C
- C - Pointers
- C - Pointers and Arrays
- C - Applications of Pointers
- C - Pointer Arithmetics
- C - Array of Pointers
- C - Pointer to Pointer
- C - Passing Pointers to Functions
- C - Return Pointer from Functions
- C - Function Pointers
- C - Pointer to an Array
- C - Pointers to Structures
- C - Chain of Pointers
- C - Pointer vs Array
- C - Character Pointers and Functions
- C - NULL Pointer
- C - void Pointer
- C - Dangling Pointers
- C - Dereference Pointer
- C - Near, Far and Huge Pointers
- C - Initialization of Pointer Arrays
- C - Pointers vs. Multi-dimensional Arrays
- Strings in C
- C - Strings
- C - Array of Strings
- C - Special Characters
- C Structures and Unions
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Self-Referential Structures
- C - Lookup Tables
- C - Dot (.) Operator
- C - Enumeration (or enum)
- C - Structure Padding and Packing
- C - Nested Structures
- C - Anonymous Structure and Union
- C - Unions
- C - Bit Fields
- C - Typedef
- File Handling in C
- C - Input & Output
- C - File I/O (File Handling)
- C Preprocessors
- C - Preprocessors
- C - Pragmas
- C - Preprocessor Operators
- C - Macros
- C - Header Files
- Memory Management in C
- C - Memory Management
- C - Memory Address
- C - Storage Classes
- Miscellaneous Topics
- C - Error Handling
- C - Variable Arguments
- C - Command Execution
- C - Math Functions
- C - String Functions
- C - Static Keyword
- C - Random Number Generation
- C - Command Line Arguments
C Programming - C Arithmetic Operators
![]() Share with a Friend |
C Programming - C Arithmetic Operators
C Arithmetic Operators
Arithmetic operators in C are used to perform basic mathematical operations such as addition, subtraction, multiplication, division, and finding the remainder. These operators work with integer, floating-point, and other numerical data types.
List of Arithmetic Operators
| Operator | Description | Example | Result |
|---|---|---|---|
|
+ |
Addition |
a + b |
Sum of a and b |
|
- |
Subtraction |
a - b |
Difference of a and b |
|
* |
Multiplication |
a * b |
Product of a and b |
|
/ |
Division |
a / b |
Quotient when a is divided by b |
|
% |
Modulus (remainder) |
a % b |
Remainder when a is divided by b |
Key Characteristics
- Addition (+): Adds two numbers.
C
int a = 5, b = 3;
printf("Sum: %d\n", a + b); // Output: 8
- Subtraction (-): Subtracts the second number from the first.
C
int a = 5, b = 3;
printf("Difference: %d\n", a - b); // Output: 2
- Multiplication (*): Multiplies two numbers.
C
int a = 5, b = 3;
printf("Product: %d\n", a * b); // Output: 15
- Division (/):
- Returns the quotient of two numbers.
- For integer division, the result is truncated (fractional part is discarded).
C
int a = 5, b = 2;
printf("Quotient: %d\n", a / b); // Output: 2
- For floating-point numbers, it returns the exact quotient.
C
float a = 5.0, b = 2.0;
printf("Quotient: %.2f\n", a / b); // Output: 2.50
- Modulus (%):
- Returns the remainder of integer division.
- Works only with integers.
C
int a = 5, b = 3;
printf("Remainder: %d\n", a % b); // Output: 2
Example Program
C
#include <stdio.h>
int main() {
int a = 10, b = 4;
float x = 10.5, y = 4.2;
printf("Addition (int): %d\n", a + b);
printf("Subtraction (int): %d\n", a - b);
printf("Multiplication (int): %d\n", a * b);
printf("Division (int): %d\n", a / b);
printf("Modulus (int): %d\n", a % b);
printf("Addition (float): %.2f\n", x + y);
printf("Subtraction (float): %.2f\n", x - y);
printf("Multiplication (float): %.2f\n", x * y);
printf("Division (float): %.2f\n", x / y);
return 0;
}
Output:
Addition (int): 14
Subtraction (int): 6
Multiplication (int): 40
Division (int): 2
Modulus (int): 2
Addition (float): 14.70
Subtraction (float): 6.30
Multiplication (float): 44.10
Division (float): 2.50
Important Notes
- Division with Integers:
- If both operands are integers, the result is an integer (truncated).
C
int a = 7, b = 3;
printf("%d\n", a / b); // Output: 2
- Floating-Point Division:
- At least one operand must be a floating-point number to retain the decimal part.
C
float a = 7.0, b = 3.0;
printf("%.2f\n", a / b); // Output: 2.33
- Modulus Operator:
- Only applicable to integers.
- Using % with floating-point numbers results in a compilation error.
- Operator Precedence:
- Multiplication, division, and modulus (*, /, %) have higher precedence than addition and subtraction (+, -).
C
int result = 10 + 5 * 2; // Evaluates as 10 + (5 * 2) = 20
- Use parentheses to enforce precedence.
C
int result = (10 + 5) * 2; // Evaluates as (10 + 5) * 2 = 30
Applications
- Arithmetic operators are fundamental in mathematical computations, such as:
- Solving equations
- Calculating percentages
- Building algorithms
- Data processing and analysis
