Immanuel Training Institute proudly presents free software courses
To get certificate Contact: iits.certificate@gmail.com
CHAPTER 1 Introduction and structure of C program
CHAPTER 2 Data types, Constants, Variables and I/OStatements
CHAPTER 3 Operators and Expressions
CHAPTER 6 String Manipulations
CHAPTER 8 Structure, Unions and Enumerated Datatypes
CHAPTER 3
OPERATORS AND EXPRESSIONS
OPERATORS:-
An operator is a symbol that specifies an operation to be performed on the operands. The data items that operates acts upon are called operands. It have 2 operands- binary operators , It have 1 operands – unary operators
TYPES
:-
· Arithmetic (+, -, *, /, %, ++, --)
· Relational (= =, !=, >, <, <=, >=)
· Logical (&&, ||, !)
· Assignment ( =, +=, -=, *=, /= )
· Conditional or ternary (?:)
· Bitwise ( &, |, ^, ~, >>, <<)
· Special ( sizeof, &, *,)
EXPRESSIONS:-
An Expression represents data item such as variables , constants and are interconnected with operators as per the syntax of the language. An expression is evaluated using assignment operator.
Ex:-
Arithmetic : c=a+b
Relational : a>b
Logical : (b<a)&&(a>c) …..etc
The precedence of operator species that which operator will be evaluated first and next. The associativity specifies the operator direction to be evaluated; it may be left to right or right to left.
|
Category |
Operator |
Associativity |
|
Postfix |
() []
-> . ++ - - |
Left
to right |
|
Unary |
+ - !
~ ++ - - (type)* & sizeof |
Right
to left |
|
Multiplicative |
* / % |
Left
to right |
|
Additive |
+ - |
Left
to right |
|
Shift |
<<
>> |
Left
to right |
|
Relational |
<
<= > >= |
Left
to right |
|
Equality |
== != |
Left
to right |
|
Bitwise
and |
& |
Left
to right |
|
Bitwise
xor |
^ |
Left
to right |
|
Bitwise
or |
| |
Left
to right |
|
Logical
and |
&& |
Left
to right |
|
Logical
or |
|| |
Left
to right |
|
Conditional |
?: |
Right
to left |
|
Assignment |
= +=
-= *= /= %=>>= <<= &= ^= |= |
Right
to left |
|
Comma |
, |
Left
to right |
TYPE CASTING (DATA TYPE CONVERSION):
It is used to convert a variable from one data type to another
data type during run time.
Syntax:
(data type)Expression
Example:
int a=10,b=3;
float c;
c=(float)a/b;
In above example variables 'a' and 'b' are integer values so it will give
integer result. When we store the result into variable 'c' which is a float type so result
will be converted into float but after decimal point values are missed. To
avoid this we are converting variable 'a' into float type during run time.
EXAMPLE PROGRAMS:
1. Write
a program to find area and circumference of the circle.
#include<stdio.h>
#include<conio.h>
void main()
{
float r,a,c;
clrscr();
printf("Enter the radius for the
circle:");
scanf("%f",&r);
a=3.14*r*r;
c=2*3.14*r;
printf("Area = %f\nCircumference =
%f",a,c);
getch();
}
2. Example
program for relational operators(>=,<=,==,!=).
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter the no.:");
scanf("%d",&a);
printf("\na>=5\t:\t%d",a>=5);
printf("\na<5\t :\t%d",a<5);
printf("\na==5\t:\t%d",a==5);
printf("\na!=5\t:\t%d",a!=5);
getch();
}
3. Write
a program to find biggest no. among two numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the a,b values:");
scanf("%d%d",&a,&b);
c=(a>b)?a:b;
printf("The biggest no. is %d",c);
getch();
}
4. Example
program for sizeof() operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
float b;
char c;
char name[10];
clrscr();
printf("Enter the integer value:");
scanf("%d",&a);
printf("Enter the float value:");
scanf("%f",&b);
printf("Enter the character:");
flushall();
scanf("%c",&c);
printf("Enter the string:");
scanf("%s",name);
printf("\nThe size of integer value
%d\n",sizeof(a));
printf("The size of float value
%d\n",sizeof(b));
printf("The size of character value
%d\n",sizeof(c));
printf("The size of character value
%d\n",sizeof(name));
getch();
}
5. Example
program for assignment operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,i,j,k;
clrscr();
printf("Enter a,b,c values:");
scanf("%d%d%d",&a,&b,&c);
i=j=k=1;
a+=i;
b+=j;
c+=k;
d=a+(e=10);
printf("\nThe increment value for a is
%d",a);
printf("\nThe increment value for b is
%d",b);
printf("\nThe increment value for c is
%d",c);
printf("\nThe value of d is %d",d);
printf("\nThe value of e is %d",e);
getch();
}
6. Example
program for increment/decrement operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter the no.:");
scanf("%d",&a);
printf("\na++\t:\t%d",a++);
printf("\n++a\t:\t%d",++a);
printf("\na--\t:\t%d",a--);
printf("\n--a\t:\t%d",--a);
getch();
}
7. Example
program for type casting:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
float c;
clrscr();
printf("Enter the a,b values:");
scanf("%d%d",&a,&b);
c=a/(float)b;
printf("The value of c is %f",c);
getch();
}
TN 10TH SAMACHEER MATHS EXERCISE 2.5 SOLUTIONS