C - Programming - Mariana Hack Tech 101
C - Programming - Mariana Hack Tech 101
Presents
1
KARIM CITY COLLEGE
Department of Computer Application
BCA Semester – 1
Group – 2
Roll No. – CACOM21007 – CACOM21012
C - PROGRAMMING
Content :-
1. Overview of C
2. Operators & Expressions
3
Overview Of
History of Language
4
Year Languag Developed by
e
5
OPERATORS in C
Operators Type
( ++ , -- ) Unary
Operators
Unary
Arithmetic
Operators
(+ ,-,*,/,%)
Operators
Operators that operate or work with a single operand are Operators that operate or work with two operands are binary operators. For
unary operators. For example: Increment(++) and example: Addition(+), Subtraction(-), multiplication(*), Division(/) operators
Decrement(– –) Operators
int a = 7;
int val = 5; ++val; // 6 int b = 2;
int val1 = 5; --val1; // 4 printf(“%d”,a + b); // 9
printf(“%d”,a – b); // 5 7
/ / Wo r k i n g o f a r i t h m e t i c o p e r a t o r s Output
#include <stdio.h>
int main() a+b = 13
{ a-b = 5
int a = 9,b = 4, c; a*b = 36
a/b = 2
c = a+b; Remainder when a divided by
printf("a+b = %d \n",c); b=1
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;
printf("Remainder when a divided by b = %d \n",c);
return 0;
}
8
Relational
Operators
These are used for the comparison of the values of two operands.
For example : checking if one operand is equal to the other operand or not, an operand is greater than the other
operand or not, etc. Some of the relational operators are (==, >= , <= , < , > )
int a = 3;
int b = 5;
a < b;
// operator to check if a is smaller than b
9
/ / Wo r k i n g o f r e l a t i o n a l o p e r a t o r s Output
#include <stdio.h>
int main() 5 == 5 is 1
{ 5 == 10 is 0
int a = 5, b = 5, c = 10; 5 > 5 is 0
5 > 10 is 0
printf("%d == %d is %d \n", a, b, a == 5 < 5 is 0
b); 5 < 10 is 1
printf("%d == %d is %d \n", a, c, a == 5 != 5 is 0
c); 5 != 10 is 1
printf("%d > %d is %d \n", a, b, a > b); 5 >= 5 is 1
printf("%d > %d is %d \n", a, c, a > c); 5 >= 10 is 0
printf("%d < %d is %d \n", a, b, a < b); 5 <= 5 is 1
printf("%d < %d is %d \n", a, c, a < c); 5 <= 10 is 1
printf("%d != %d is %d \n", a, b, a !=
b);
printf("%d != %d is %d \n", a, c, a !=
c);
printf("%d >= %d is %d \n", a, b, a >=
b);
printf("%d >= %d is %d \n", a, c, a >= 10
Logical
Operators
Logical operators are used to evaluate two or more
conditions.
The result of the operation of a logical operator is a Boolean value either true or false.
For example : the logical AND represented as ‘&&’ operator in C returns true when both the conditions under
consideration are satisfied. Otherwise, it returns false. Therefore, a && b returns true when both a and b are true.
11
/ / Wo r k i n g o f l o g i c a l o p e r a t o r s
#include <stdio.h> Output
int main()
{ (a == b) && (c > b) is 1
int a = 5, b = 5, c = 10, result; (a == b) && (c < b) is 0
result = (a == b) && (c > b); (a == b) || (c < b) is 1
printf("(a == b) && (c > b) is %d \n", result); (a != b) || (c < b) is 0
result = (a == b) && (c < b); !(a != b) is 1
!(a == b) is 0
printf("(a == b) && (c < b) is %d \n" , result);
result = (a == b) || (c < b);
printf("(a == b) || (c < b) is %d \n" , result);
result = (a != b) || (c < b);
printf("(a != b) || (c < b) is %d \n" , result);
result = !(a != b);
printf("!(a != b) is %d \n", result);
result = !(a == b);
printf("!(a == b) is %d \n", result);
return 0;
}
12
Bitwise
Operators
The Bitwise operators are used to perform bit-level operations on the
operands.
The operators are first converted to bit-level and then the calculation is performed on the operands.
The mathematical operations such as addition, subtraction, multiplication, etc. can be performed at bit-level for faster processing.
For example: the bitwise AND represented as & operator in C takes two numbers as operands and does AND on
every bit of two numbers. The result of AND is 1 only if both bits are 1.
13
Bitwise AND
12 = 00001100 (In Binary)
#include <stdio.h>
25 = 00011001 (In Binary)
int main()
{
Bit Operation of 12 and 25 Output =
int a = 12, b = 25;
00001100 8
printf("Output = %d",
& 00011001
a&b);
________
return 0;
00001000 = 8 (In
}
decimal)
Bitwise OR
12 = 00001100 (In Binary)
#include <stdio.h> 25 = 00011001 (In Binary)
int main()
{ Bitwise OR Operation of 12 Output =
int a = 12, b = 25; and 25 29
printf("Output = %d", a|b); 00001100
return 0; | 00011001
} ________
00011101 = 29 (In decimal) 14
Assignment
OperatorsAssignment operators are used to assigning value to a
variable.
Different types of assignment operators are shown
below:
A. “=” : This operator is used to assign the value on the right to the variable on the
left.
a = 10;
For b = 20;
example: ch = 'y';
“+=”:This operator first adds the current value of the variable on left to the value on the right and then
B. assigns the result to the variable on the left.
D. “*=”: This operator first multiplies the current value of the variable on left to the value on the right and
then assigns the result to the variable on the left.
“/=”: This operator first divides the current value of the variable on left by the value on the right and
E.
then assigns the result to the variable on the left.
High priority : * / %
Low priority : + -
18
#include <stdio.h> Output
int main()
{ Value of (a + b) * c / d is : 90
int a = 20; Value of ((a + b) * c) / d is :
int b = 10; 90
int c = 15; Value of (a + b) * (c / d) is :
int d = 5; 90
int e; Value of a + (b * c) / d is : 50
e = (a + b) * c / d; // ( 30 * 15 ) / 5
printf("Value of (a + b) * c / d is : %d\n", e );
e = ((a + b) * c) / d; // (30 * 15 ) / 5
printf("Value of ((a + b) * c) / d is : %d\n" ,
e );
e = (a + b) * (c / d); // (30) * (15/5)
printf("Value of (a + b) * (c / d) is : %d\n", e );
e = a + (b * c) / d; // 20 + (150/5)
printf("Value of a + (b * c) / d is : %d\n" , e );
return 0;
} 19
Thank You
Presented By:
BCA Students Semester -1
(CACOM21007 – CACOM21012)
20