C language operators with examples
a) Arithmetic operation:-
These operators to calculate mathematical operations.these are-, +,*,%,÷.Subtraction(-)
- it is used to subtract two operands
- A-B=1
- A=3,B=2
Addition (+)
- It is useful to add two operands
- A+B=5 (refer example 3)
Multiplication (*)
- It is used to multiplies two operandsA*B=6
Division (/)
- It is used to divides numerator by de-numerator
- A/B=1 (refer example 1&2)
%Remainder
- It is useful to get remainder
- A%B=0
Example 1)Division:-
int a, b;
float c;
c=a/b
Result :
a=10
b=3
3.000
To get 3.333 in result
We have to small change see below program
We have to small change see below program
Example 2)Division
Int a, b;Float c;
c=a/b*1.0
Example 3)Addition:-
int a, b;float c;
C=a+b
b ) Relational operators
These operators are used to compare two Numbers, ==,>,>,<if the condition is true them the result will be 1 otherwise result will be 0
Example 1)
int a, b, c;a=10;
b=3;
c=a==b;
Now c is zero condition is false
Example 2)
int a,b,c;a=100;
b=55;
c=a> b;
now c is one because condition is true;
C) Logical operators
In these operations, every operator perform different operation&&
||
!
Truth table for && operator
T T T
T F F
F T F
F F FTruth table for | operator
T T TT F T
F T T
Example 1
int a,b,c;a=100;
b=400;
c=a==b&&b> 300;
Now c=0; because condition is false
Note: In these example1 we are using && operator
Example 2
int a,b,c;a=100
b=400
c=a== b|| b> 300;
Now c=1, observe conditions b> 300 satisfied so result is true
D) Bit wise operators
These operators are performed on bitsExample 1)
a=25;b=13;
c=a/b;
Result is 29
Explanation
25→11001
13→01001
11101
F) Increment & Decrement operators
++,--,
These operators are urinary operator which is used to perform increase or Decrease by one
Increment (++) operator
These operators used to increase the value by one.It divided into two types
post-increment and pre-increment
It is used to store particular values
C Language Data Types
Integer:
- A value without a decimal point is called an integer.
- The range of integer is -3200768 to 3200767
- The declaration integer of int a, b
- 2 bytes of memory will be allocated that is 16 bytes
- Integer format %d
Float:-
- A value which contains a decimal point is called as float
- 4 bytes of memory will be allocated 32 bites
- Range is -3.4e+32 to 3.4e32
- The declaration of float is d, e, f
- Integer format %f (Decimal values)
Character:
- In this, we can access A-Z a-z 0-9
- 1 byte of memory will be allocated
- Range is -128 to 127
- Character format %c
Token keys:
The token is nothing but giving a name for variables, functions, pointer, structures. ..etc
This one is also called as a naming specifications
This one is also called as a naming specifications
Rules for naming specifications/Tokens
- It should start with alphabet (refer example 1)
- You can give numbers one special character called (-) underscore
- No spaces are available (refer example 2)
- Case sensitive
Example 1
Int 1 ✘
Int 1A ✘
Int Sum ✘
Int 1A ✘
Example 2:
Int Sum ✘
Comments
Post a Comment