Explain Operator and Expressions in c Programming
Explain Operator and Expressions in c Programming
context (Tuesday, April 15, 2025, 11:39 AM IST, Bhubaneswar, Odisha, India). These are
fundamental concepts for performing computations and making decisions in your C programs.
1. Operators in C:
● Definition: Operators are special symbols that perform specific operations on one or
more operands (variables, constants, or other expressions). They are the verbs of the C
language, allowing you to manipulate data.
● Categories of Operators in C:
○ Arithmetic Operators: These perform mathematical calculations.
■ + (Addition)
■ - (Subtraction)
■ * (Multiplication)
■ / (Division)
■ % (Modulo - gives the remainder of integer division)
■ ++ (Increment - increases the operand by 1)
■ -- (Decrement - decreases the operand by 1)
int a = 10, b = 5;
int sum = a + b; // sum is 15
int difference = a - b; // difference is 5
int product = a * b; // product is 50
int quotient = a / b; // quotient is 2
int remainder = a % b; // remainder is 0
a++; // a becomes 11
b--; // b becomes 4
○ Relational Operators: These compare two operands and return a boolean value
(true or false), represented as 1 (true) or 0 (false) in C.
■ == (Equal to)
■ != (Not equal to)
■ > (Greater than)
■ < (Less than)
■ >= (Greater than or equal to)
■ <= (Less than or equal to)
int x = 7, y = 12;
int isEqual = (x == y); // isEqual is 0 (false)
int isNotEqual = (x != y); // isNotEqual is 1 (true)
int isGreater = (y > x); // isGreater is 1 (true)
int isLessOrEqual = (x <= 7); // isLessOrEqual is 1 (true)
○ Special Operators:
■ sizeof(): Returns the size (in bytes) of a variable or data type.
■ & (Address-of operator): Returns the memory address of a variable.
■ * (Dereference operator): Accesses the value at a memory address (used
with pointers).
■ . (Member access operator): Accesses members of a structure or union.
■ -> (Pointer to member access operator): Accesses members of a structure or
union through a pointer.
■ , (Comma operator): Separates expressions in a list (the value of the entire
expression is the value of the rightmost expression).
2. Expressions in C:
● Definition: An expression is a combination of operands (variables, constants, function
calls) and operators that evaluates to a single value.
● Types of Expressions:
○ Constant Expressions: Consist only of constant values (literals) and constant
operators. Their value is determined at compile time.
5 + 3 // Evaluates to 8
'A' // Evaluates to the ASCII value of 'A'
3.14 * 2 // Evaluates to 6.28
○ Function Call Expressions: Invoke a function and evaluate to the value returned
by the function.
sqrt(25.0) // Evaluates to 5.0
printf("Hello") // Evaluates to the number of characters
printed (though often the return value is ignored)
Understanding operators and expressions is crucial for writing C programs that can perform
calculations, make comparisons, and manipulate data effectively right here in Bhubaneswar, or
anywhere your C code might run! They are the building blocks of the logic and functionality of
your programs.