- Operators
Operators in C can be categorized into several types based on their functionality:
- Arithmetic Operators:
Used for performing mathematical calculations:
Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus (%)
- Relational Operators:
Used for comparing values:
Equal to (==), Not equal to (!=), Greater than (>), Less than (<), Greater than or equal to (>=), Less than or equal to (<=)
- Logical Operators:
Used to combine multiple conditions:
Logical AND (&&), Logical OR (||), Logical NOT (!)
- Assignment Operators:
Used to assign values to variables:
Assignment (=), Addition assignment (+=), Subtraction assignment (-=), Multiplication assignment (*=), Division assignment (/=), Modulus assignment (%=)
- Increment and Decrement Operators:
Used to increase or decrease the value of a variable:
Increment (++), Decrement (--)
- Bitwise Operators:
Used for manipulation of bits in integers:
Bitwise AND (&), Bitwise OR (|), Bitwise XOR (^), Bitwise NOT (~), Left shift (<<), Right shift (>>)
- Ternary Operator:
Conditional operator for decision making:
condition ? expression1 : expression2
- Control Flow Statements
Control flow statements dictate the order in which statements in your code are executed based on certain conditions or loops. Key control flow statements in C include:
- Conditional Statements:
- if statement:
- if-else statement:
- else-if ladder:
- Switch Statement:
Used to select one of many code blocks to be executed:
- Loops:
- while loop:
Executes a block of code as long as a specified condition is true.
- do-while loop:
Similar to the while loop but guarantees that the block of code is executed at least once before checking the condition.
- for loop:
Executes a block of code a specified number of times.