C Tutorial
Estimated reading: 4 minutes 6 views

โž• C Operators โ€“ Expression Control in C Programming


๐Ÿงฒ Introduction โ€“ What Are Operators in C?

Operators in C are special symbols or keywords used to perform actions on dataโ€”such as mathematical computations, logic checks, and value assignments. These operators form the foundation of all expressions and decision-making logic in C programs.

๐ŸŽฏ In this guide, youโ€™ll learn:

  • What operators are and why they matter
  • Different categories of operators in C
  • Practical usage of operators with examples
  • How operator precedence impacts expression evaluation

๐Ÿ“˜ Topics Covered

๐Ÿ”ข Topic๐Ÿ“„ Description
โž— C Arithmetic OperatorsUsed for basic mathematical operations
๐Ÿ“Š C Relational OperatorsUsed to compare values
๐Ÿ” C Logical OperatorsCombines or negates Boolean expressions
๐Ÿงฎ C Bitwise OperatorsOperates at bit-level for integer types
๐Ÿ“ C Assignment OperatorsAssigns values to variables
โž• C Unary & Ternary OperatorsOperates on one or three operands
๐Ÿ“ C sizeof OperatorReturns size of a type or variable
๐Ÿงฉ C Operator PrecedenceDetermines order of operation execution

โž— C Arithmetic Operators

Used for standard mathematical operations.

OperatorOperationExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Modulusa % b (remainder)

๐Ÿง  Note: Division of integers results in integer division.


๐Ÿ“Š C Relational Operators

Used to compare values, returning 1 for true and 0 for false.

OperatorMeaningExample
==Equal toa == b
!=Not equala != b
>Greater thana > b
<Less thana < b
>=Greater or equala >= b
<=Less or equala <= b

๐Ÿง  Used commonly in if and while statements.


๐Ÿ” C Logical Operators

Used to perform logical operations on Boolean expressions.

OperatorMeaningExample
&&Logical ANDa > 0 && b < 10
``
!Logical NOT!isReady

โœ… Useful in conditional branching and validations.


๐Ÿงฎ C Bitwise Operators

Performs operations at the bit-level (works on integers).

OperatorMeaningExample
&Bitwise ANDa & b
``Bitwise OR
^Bitwise XORa ^ b
~Bitwise NOT~a
<<Left Shifta << 1
>>Right Shifta >> 2

๐Ÿ’ก Useful in embedded and system programming.


๐Ÿ“ C Assignment Operators

Used to assign values to variables. Can also combine with arithmetic operations.

OperatorMeaningExample
=Assigna = 10
+=Add and assigna += 5
-=Subtract and assigna -= 3
*=Multiply and assigna *= 2
/=Divide and assigna /= 4
%=Modulus and assigna %= 2

๐Ÿ” Reduces redundancy in code by combining operations.


โž• C Unary & Ternary Operators

๐Ÿ”ธ Unary Operators

Work with a single operand.

OperatorMeaningExample
++Incrementa++ or ++a
--Decrementb-- or --b
!Logical NOT!flag
-Unary minus-a

๐Ÿ”น Ternary Operator

Used as a shorthand for if...else.

๐Ÿงช Syntax:

(condition) ? value_if_true : value_if_false;

โœ… Example:

int max = (a > b) ? a : b;

๐Ÿ“ C sizeof Operator

Returns the memory size (in bytes) of a data type or variable.

โœ… Syntax:

sizeof(type_or_variable);

๐Ÿงช Example:

printf("%lu", sizeof(int));  // Usually prints 4

๐Ÿ“˜ Helps optimize memory usage.


๐Ÿงฉ C Operator Precedence

Defines the order of operations when multiple operators are used in an expression.

๐Ÿง  Example:

int result = 5 + 2 * 3;  // result = 11

โœ๏ธ Use parentheses to override precedence:

int result = (5 + 2) * 3;  // result = 21

๐Ÿ“˜ Refer to the C operator precedence table for full order.


๐Ÿ“Œ Summary โ€“ Recap & Next Steps

C operators allow you to build powerful expressions that drive logic and computation in your programs. From arithmetic to bitwise operations and complex conditionals, mastering operators is key to writing efficient C code.

๐Ÿ” Key Takeaways:

  • Operators act on operands to manipulate or evaluate data
  • C has unary, binary, and ternary operators
  • sizeof helps determine memory size for optimization
  • Precedence rules affect how expressions are computed
  • Bitwise and logical operators are powerful in low-level programming

โš™๏ธ Real-World Relevance:
Operators are foundational in embedded systems, hardware control, financial calculations, and even game development logic.


โ“ Frequently Asked Questions (FAQ)


โ“ What is an operator in C?
โœ… An operator is a symbol that tells the compiler to perform a specific operation. Examples: +, -, =, &&, !.


โ“ How many types of operators are there in C?
โœ… Eight major types: Arithmetic, Relational, Logical, Bitwise, Assignment, Unary, Ternary, and sizeof.


โ“ Whatโ€™s the difference between = and ==?
โœ… = is an assignment operator; == is a comparison operator that checks for equality.


โ“ Why does operator precedence matter?
โœ… Without proper understanding or use of parentheses, expressions may yield unexpected results due to automatic evaluation order.


โ“ What is a ternary operator?
โœ… A concise form of if...else:

(condition) ? value1 : value2;

โ“ Can I use bitwise operators on floating-point numbers?
โœ… No. Bitwise operations work only with integer data types.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

โž• C Operators

Or Copy Link

CONTENTS
Scroll to Top