Constant values used within a program are known as Literals. These constant values occupy memory but do not have any reference like variables. Or as Wikipedia speaks literal is a notation for representing a fixed value within a source code.
There are four types of literals in C programming.
- Integer literal
- Float or real literal
- Character literal
- String literal
Continue reading Literals in C programming
Order of evaluation of operations can alter the final result. For example, consider evaluating following expression without any mathematics rule.
5 + 3 * 4 / 2
If you do not follow any specific rule to evaluate such expressions, then you probably lead to ambiguous result. Such as one might think it will evaluate either 32 or 11 or 18.5 etc.
To overcome such ambiguity, in mathematics we follow BODMAS rule. Similarly, in computer programming we follow operator precedence and associativity rule.
Continue reading Operator precedence and associativity in C
Conditional operator is a ternary operator. It is used to evaluate an expression based on some condition.
Syntax of conditional operator
<conditional-expression> ? <expression1> : <expression2>
Continue reading Conditional operator in C
Increment and Decrement operator are used to increment or decrement value by 1.
There are two variants of increment/decrement operator.
- Prefix (pre-increment and pre-decrement)
- Postfix (post-increment and post-decrement)
Syntax of using increment/decrement operator
-- operators are used with variables. Using
-- with constant will result in error. Such as expressions like
(a + b)++ etc. are invalid and causes compilation error.
Continue reading Increment and Decrement operator in C
We use Bitwise operators to manipulate data at its lowest level (bit level). Bitwise operators works on each bit of the data.
Data in the memory (RAM) is organized as a sequence of bytes. Each byte is a group of eight consecutive bits. Bitwise operators are useful when we need to perform actions on bits of the data.
Bitwise operators work with integer type. They do not support float or real types.
Continue reading Bitwise operators in C
Relational operators are good at comparing two quantities. However, relational operators does not support comparison of three or more quantities.
For example, suppose you need to check range of a number. You need to check whether a number n is in between 1-100 or not. For that you must check two conditions, first check if n > 1 finally check if n < 100.
We use logical operators to combine two or more relational expressions as a single relational expression. Logical operators evaluates a Boolean value (integer in case of C) depending upon the operator used.
Continue reading Logical operators in C
In real life, we often compare two different quantities and depending on their relation, we take some decisions. For example, we compare the price of two items, age of two persons etc. Relational operators supports these comparisons in C programming.
We use relational operators to compare two constants, variables or expressions. We generally compare two quantities of similar nature. Likewise, relational operators can only compare any two similar types. It evaluates Boolean value either true or false depending on their relation. Based on evaluated Boolean result we take decisions or execute some statements.
In C programming, there is no concept of Boolean values. C represents false with 0 and true with a non-zero integer value.
Continue reading Relational operators in C
Assignment operator is used to assign value to a variable (memory location). There is a single assignment operator
= in C. It evaluates expression on right side of
= symbol and assigns evaluated value to left side the variable.
Continue reading Assignment and shorthand assignment operator in C
Arithmetic operators are used to perform basic arithmetic operations. Operations like addition, subtraction, multiplication, division and modulo division.
C supports five arithmetic operators.
|Unary plus or binary addition
|Unary minus or binary subtraction
|Modulo division (Evaluates remainder)
Continue reading Arithmetic operators in C
Every C program is developed using five fundamental units keywords, identifiers, operators, separators and literals. In previous post, we already learned about keywords and identifiers. Here in this post we will focus on operators and separators.
Continue reading Operators and separators in C programming