Constants and operators are highly significant parts of the C language, which have fixed constants and employ operators for computations.
We’ll go through operators and constants one by one in this article. You will be able to understand all of the idea operators and constants in C programming at the end of this tutorial.
Table of Contents
Constants in C
What are constants in C? A constant in C language is a fixed value that does not change while the program is running. The following are the parts of the C constants:
- Integer Constant
- Real Constant
- Character Constant
- String Constant
A sequence of digits is referred to as an integer constant. There are three different types of integer constants.
- Decimal Integers Constant
- Octal Integer Constant
- Hexadecimal Integer Constant
Decimal Integer Constant
A decimal integer constant is made up of a collection of numbers ranging from 0 to 9, each followed by a – or + sign. + and – are optional here. Spaces, Commas and non-digit characters are not permitted between digits in decimal integer constant.
10 -302 +32 0
Octal Integer Constant
An octal integer constant is made up of any number of digits from 0 to 7, including a leading zero (0).
Hexadecimal Integer Constant
A hexadecimal integer is a set of numbers prefixed by the letters 0x or 0X. They might also include the letters a to f or A to F. The numerals 10 through 15 are represented by the letters A through F.
0X5 0X5A 0x5b
Floating-point constants are another name for real constants. The real constants can be expressed in two ways:
- Fractional Form
- Exponential Form
There must be at least one digit and a decimal point in a fractional form. It might be either a positive or a negative item. Positive is the default sign. In a real constant, no commas, non-digit characters, or blanks are permitted.
+457.05 -54.75 .21
The exponential form of representation of real constants is employed when the value of the constant is either too small or too large. The real constant is expressed in two parts in exponential manner of representation. Mantissa refers to the component that appears before ‘e,’ whereas exponent refers to the part that appears after ‘e.’ The mantissa sign can be either positive or negative. Positive is the default sign. At least one digit must be a positive or negative integer in the exponent. Positive is the default sign. In exponential form, the range of real constants is 3.4e38 to 3.4e38.
A single character constant is made up of a single character contained by two single quotation marks.
A string constant is a collection of characters surrounded by double quotes. Letters, numerals, special characters, and blank space can all be used as characters.
"geek" "329.30" "32"
Backslash Character Constant/Escape Sequences
The double quotation (“), the apostrophe (‘), the question mark (?) and the backslash () are examples of non-printing characters that can be described in terms of escape sequence.
|1||\a||Bell (audible alert)|
|4||\n||New line (line feed)|
|6||\f||Form feed(new page)|
|7||\”||Quotation mark (double quote)|
Constants and Operators in C Language
Operators in C
What is operator and its example? An operator is a symbol that instructs the computer to conduct mathematical or logical calculations. They are used to alter data and variables in programs. The following are the different types of operators in ‘C’:
- Arithmetic Operator
- Relational Operator
- Logical Operator
- Assignment Operator
- Increment and Decrement Operator
- Bitwise Operator
- Conditional Operator
- Comma Operator
- Sizeof Operator
|1||+||Addition||a + b|
|2||–||Subtraction||a – b|
|3||*||Multiplication||a * b|
|4||/||Division||a / b|
|5||%||Modulus||a % b|
|1||==||is equal to||a == b|
|2||>||is greater than||a > b|
|3||>=||is greater than or equal to||a >= b|
|4||<||is less than||a < b|
|5||<=||is less than or equal to||a <= b|
|1||=||z= x + y will assign value of x + y into z|
|2||+=||x += 10 is equivalent to x = x + 10|
|3||-=||x -= 10 is equivalent to x = x – 10|
|4||*=||x *= 10 is equivalent to x = x * 10|
|5||/=||x /= 10 is equivalent to x = x / 10|
|6||%=||x %= 10 is equivalent to x = x % 10|
|7||&=||x &= 10 is equivalent to x = x & 10|
|8|||=||x |= 10 is equivalent to x = x | 10|
|9||^=||x ^= 10 is equivalent to x = x ^ 10|
|10||<<=||x <<= 10 is equivalent to x = x << 10|
|11||>>=||x >>= 10 is equivalent to x = x >> 10|
Increment and Decrement Operator
Bitwise and Bit Shift Operator
|1||~||Unary bitwise complement|
|2||<<||Signed left shift|
|3||>>||Signed right shift|
|5||^||Bitwise exclusive OR|
|6|||||Bitwise inclusive OR|
In conclusion, Hope you liked the article “Constants and Operators in C Language”. We will keep updating this page.
If you have any doubts and questions regarding operators and constants, feel free to contact us.