0% found this document useful (0 votes)
34 views20 pages

C - Programming - Mariana Hack Tech 101

The document summarizes key concepts about C programming language including: 1. It provides an overview of the history and development of C language from 1960 to 1990 by different groups and committees. 2. It describes different types of operators in C like arithmetic, relational, logical, bitwise and assignment operators giving examples of each. 3. It shows code snippets to demonstrate the working of arithmetic, relational, logical and bitwise operators in C programs and explains the output.

Uploaded by

namiy38728
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views20 pages

C - Programming - Mariana Hack Tech 101

The document summarizes key concepts about C programming language including: 1. It provides an overview of the history and development of C language from 1960 to 1990 by different groups and committees. 2. It describes different types of operators in C like arithmetic, relational, logical, bitwise and assignment operators giving examples of each. 3. It shows code snippets to demonstrate the working of arithmetic, relational, logical and bitwise operators in C programs and explains the output.

Uploaded by

namiy38728
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

BCA Students

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

C programming language was developed in 1972 at bell laboratories


of AT&T(American Telephone & Telegraph), located in the U.S.A.

Dennis Ritchie is known as the founder of the C language.

4
Year Languag Developed by
e

1960 ALGOL International Group

1967 BCPL Martin Richard

1970 B Ken Thompson

1973 Traditional Dennis Ritchie

1989 C or C89 ANSI Committee

1990 ISO C ISO Committee

5
OPERATORS in C
Operators Type
( ++ , -- ) Unary
Operators
Unary
Arithmetic
Operators
(+ ,-,*,/,%)
Operators

( < , <= , > , >= , == , != ) Relational


Operators
Logical
( && , || , ! ) Binary
Operators
Bitwise Operators
( &, | , ^ , << , >> , ~ )
Operators
Assignment
( = ,+= ,-= ,*= ,/= ,%= )
Operators
Ternary or Conditional
?: Operators Ternary
Operators 6
Arithmetic
Operators
These operators are used to perform arithmetic / mathematical operations on operands.

Examples: (+, -, *, /, %,+


+,–).
Arithmetic operators are of two
types:

Unary Operators Binary 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.

(4 != 5) && (4 < 5); // 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.

int a = 5, b = 9; // a = 5(00000101), b = 9(00001001)


printf(“%d”,a ^ b); // 00001100 //Bitwise XOR
printf(“%d”,~a); // 11111010 //Bitwise Complement

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.

For (a += b) can be written as (a = a + b)


example: 15
“-=”: This operator first subtracts the value on the right from the current value of the variable on left
C.
and then assigns the result to the variable on the left.

For (a -= b) can be written as (a = a - b)


example:

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.

For (a *= b) can be written as (a = a * b)


example:

“/=”: 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.

For (a /= b) can be written as (a = a / b)


example:
16
/ / Wo r k i n g o f a s s i g n m e n t o p e r a t o r s
#include <stdio.h>
int main()
{ Output
int a = 5, c;
c=5
c = a; // c is 5 c = 10
printf("c = %d\n", c); c=5
c += a; // c is 10 c = 25
printf("c = %d\n", c); c=5
c -= a; // c is 5 c=0
printf("c = %d\n", c);
c *= a; // c is 25
printf("c = %d\n", c);
c /= a; // c is 5
printf("c = %d\n", c);
c %= a; // c = 0
printf("c = %d\n", c);
return 0;
}
17
Operators
Precedence
At first, the expressions within parenthesis are evaluated. If no parenthesis is present, then the arithmetic
expression is evaluated from left to right.

There are two priority levels of operators in C.

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

You might also like