C-Programming
In this tutorial, you will learn:
Operators:-
Operator are sign which is used to generate an expression or to perform any calculation.
For example:- x=y+z;
Types of operator on the basis of expression performance:-
1. Uninary operator:-
When a single variable or operands use and operator is known as Uninary operator
For example:- {x++ or ++x}
{x-- or --x}
2. Binary operator:-
When more than one or two variable or operands uses any opeartors to generate an expression known as Binary operator.
For example: x=x+1;
x=a+b;
There are some types operator available in C.
* Airthmatic operator (+, -, /, *)
For example:-
int x=1, y=1, s;
s=x+y; ------------(here we use additional operator).
* Relational operator (>, <, <=, >=)
Relational operator are used for comparison of two values to understand the type of relationship.
A simple defintion is here we are omparing two value and two operand and in last we get result which one is greater, smaller, etc.
For example:-
int x=1, y=3;
if(x>y)
{
printf("x is greater");
}
else
{
printf("y is greater");
}
OUTPUT:-
Y is greater.
* Logical operator {AND(&&), OR(||), NOT(!)}
For example:
int x=10, y=100;
if(x=10 && y>x)
{
printf("code with abhi")
}
else
{
printf("wrong choice");
}
OUTPUT:
Code with abhi
* Increment / Decrement (--, ++)
The increment operator add +1 to it's operands whereas, The decrement operator subtract -1 to it's operator.
For example:
int x=1;
for(x=1;x<5;x++) ------here we use increment operator.
{
printf("%d",x);
}
OUTPUT:
1
2
3
4
* Assignment operator (=)
An Assignment operator is used to assign value to a variable.
For example:
int x=1; ------- assignment operator
printf("%d",x);
}
OUTPUT:
1
* Equality operator (==)
The equality perator is used to compare two values or expression.
For example:
Int x=10, y=100;
if(x==y);
{
printf("10");
}
else
{
printf("0");
}
OUTPUT:
0
* Short hand operator
The shorthand operator is used to express anything in shorter way.
For example:
int x=10;
x=+1;
printf("%d",x);
OUTPUT:
11
* Conditional / Ternary operator
The conditional operator is used for check whthere condition is triue or false. Ternary operator is used to test a condition either condtion will be true or false. In ternary operator they have to use (? , :) sign for execute the true or false condition by using the following syntax.
(Ternary operator is subsitiute of if else)
Syntax:-
(Condition test) ? (statement 1) : (statement 2) ;
For example:-
#include<stdio.h>
#include<conio.h>
void main()
{
int l, x=50 ; y=20;
l=(x>y) ? x : y ;
printf('largest no is = %d",l);
getch();
}
OUTPUT
Largest no is = x
0 comments:
Post a Comment
If you have any doubt, please let me know