C Tutorial
Estimated reading: 4 minutes 343 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 :
Share

โž• C Operators

Or Copy Link

CONTENTS
Scroll to Top