LET US STUDY C PROGRAMMING 4 Operators
In the last section a program we are written in the program some function are used that are
clrscr() means clear screen.
getch() means get character.
printf() means printing.
scanf() means scan what we are using in the program.
%d decimal integers
%x hex integer
%f float and double number
How to specify display space for a variable?
printf(“The student id is %5d \n”, stud_id);
The value of stud_id will occupy 5 characters space in the print-out.
It introduces a new line on the terminal screen.
|\a||alert (bell) character||\\||backslash|
|\r||carriage return||\000||octal number|
|\t||horizontal tab||\xhh||hexadecimal number|
What is operator and its duty
The operator is used for what specific activity want to run. may be logical operation or mathematical. An operator is a symbol example + this operator is used for addition and ++ for increment etc.The operators are using in c program are.
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Increment and Decrement Operators
- Misc Operators
An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication etc.
|Operator||Meaning of Operator|
|+||addition or unary plus|
|–||subtraction or unary minus|
|%||remainder after division (modulo division)|
example program using operator for addition.
printf(“Enter two numbers to add\n”);
scanf(“%d%d”, &a, &b);
c = a + b;
printf(“Sum of the numbers = %d\n”, c);
A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false returns 0.
|Operator||Meaning of Operator||Example|
|!=||Not equal to||
|>=||Greater than or equal to||
|<=||Less than or equal to||
An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false.
|&&||Logical AND. True only if all operands are true||If c = 6and d = 2 then, expression
|||||Logical OR. True only if either one operand is true||If c = 7and d = 3 then, expression
|!||Logical NOT. True only if the operand is 0||If c =7 then, expression
During computation, mathematical operations like: addition, subtraction, multiplication, division, etc are converted to bit-level which makes processing faster and saves power.Bitwise operators are used in C programming to perform bit-level operations.
|Operators||Meaning of operators|
|^||Bitwise exclusive OR|
An assignment operator is used for assigning a value to a variable. The most common assignment operator is
|=||a = b||a = b|
|+=||a += b||a = a+b|
|-=||a -= b||a = a-b|
|*=||a *= b||a = a*b|
|/=||a /= b||a = a/b|
|%=||a %= b||a = a%b|
Increment and Decrement Operators
C programming has two operators increment
++ and decrement
-- to change the value of an operand (constant or variable) by 1.
++ increases the value by 1 whereas decrement
-- decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.
Misc Operators ↦ sizeof & ternary
Besides the operators discussed above, there are a few other important operators
|sizeof()||Returns the size of a variable.||sizeof(x, where a is integer, will return 6|
|&||Returns the address of a variable.||&a; returns the actual address of the variable.|
|*||Pointer to a variable.||*a;|
|? :||Conditional Expression.||If Condition is true ? then value X : otherwise value Y|