INTRODUCTION OF C
đHistory of C Language
Developed by: Dennis Ritchie
Year: 1972
Place: Bell Laboratories, USA
Purpose: Initially developed to rewrite the UNIX operating
system.
3.
FEATURES OF C
LANGUAGE
1.Simple and Easy to Learn
2. Procedural Programming Language
3. Fast and Efficient
4. Portable â Programs can run on different machines.
5.recursion
6.Middle-Level Language
7. Low-Level Memory Access
4.
PURPOSE OF CLANGUAGE
đ¯
The C programming language was designed to help
developers write efficient, powerful, and portable software. It
is still widely used
â Main Purposes of C Language
1. System Programming used to create operating systems,
device drivers, and compilers.
2.C is fast and efficient, making it ideal for game
development, real-time simulations, and graphics
WHAT IS OPERATORS?
1)Operators in C are symbols or special characters used to
perform operations on variables and values.
2)They tell the compiler to perform mathematical, logical,
relational, or bitwise operations.
7.
what is operatorprecedence ?
Definition:
Operator precedence defines which operator is evaluated first in an expression
when two or more operators appear together.
Why It's Important:
Without parentheses, C uses precedence rules to decide what happens first. For
example:
int result = 10 + 5 * 2; // result = 10 + (5 * 2) = 20
8.
How it's work?đ Operator Precedence (From Highest to Lowest)
Precedence Level Operators Associativity
1 (Highest) () (parentheses), [], . , -> Left to
Right
2 ++, --, + (unary), - (unary), !, ~, sizeof Right to
Left
3 *, /, % Left to Right
4 +, - Left to Right
5 <, <=, >, >= Left to Right
6 ==, != Left to Right
7 && Left to Right
8 `
9 ?: (Ternary/Conditional) Right to Left
10 =, +=, -=, *=, /=, etc. Right to Left
11 (Lowest) , (comma) Left to Right
10.
1) Arithmetic operator:
1) Used to perform mathematical calculations like addition, subtraction, multiplication, division, and remainder.
2)Operators include:
+ (Addition)
- (Subtraction)
* (Multiplication)
/ (Division)
% (Modulus - gives remainder)
11.
#include <stdio.h>
int main(){
int a = 10, b = 5;
printf("Addition: %dn", a + b);
printf("Subtraction: %dn", a - b);
printf("Multiplication: %dn", a * b);
printf("Division: %dn", a / b);
printf("Modulus: %dn", a % b);
return 0;
}
Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2
Modulus: 0
Example program
Output
12.
I) logical operatorsin C are used to perform logical operationsâusually in conditional expressions like if, while, etc.
2) They combine two or more conditions (expressions) and return either true (1) or false (0).
2) Logical operator
1)&&(and)
2)||(or)
3)!(not)
Types of logical operator
13.
#include <stdio.h>
int main(){
int a = 5, b = 10;
if (a > 0 && b > 0)
printf("Both numbers are positive.n");
if (a < 0 || b > 0)
printf("At least one number is positive.n");
if (!(a < 0))
printf("a is not negative.n");
return 0;
}
Example
Output
Both numbers are positive.
At least one number is positive.
a is not negative.
14.
3) Relational operators
DEF:Relational operators in C are used to compare two values or expressions.
The result of a relational operation is either true (1) or false (0).
1)+=
2)-=
3)==
4)>
5)<
6)>=
7)<=
Types of Relational operators
15.
#include <stdio.h>
int main(){
int a = 5, b = 10;
if (a < b)
printf("a is less than bn");
if (a != b)
printf("a is not equal to bn");
if (b >= a)
printf("b is greater than or equal to an");
return 0;
}
Example
a is less than b
a is not equal to b
b is greater than or equal to a
Output
16.
4)Increment & decrementoperators
In C language, increment and decrement operators are
used to increase or decrease the value of a variable by 1.
DEFINITION:
Types of operators
1) ++
2)--
17.
#include <stdio.h>
int main(){
int a = 5;
printf("Original value: %dn", a);
printf("Post-increment: %dn", a++);
printf("Pre-decrement: %dn", --a);
return 0;
}
Original value: 5
Post-increment: 6
Pre-decrement: 5
Example program
Output
18.
5) Size ofoperators
DEFINITION:
The sizeof operator in C is a compile-time unary operator that is used to
determine the memory size (in bytes) of a data type or variable.
syntax:
sizeof(data_type)
sizeof(variable)
19.
#include <stdio.h>
int main(){
int a;
float b;
char c;
printf("Size of int: %lu bytesn", sizeof(int));
printf("Size of float: %lu bytesn", sizeof(b));
printf("Size of char: %lu bytesn", sizeof(c));
return 0;
}
Size of int: 4 bytes
Size of float: 4 bytes
Size of char: 1 byte
Example program
Output
20.
6) Conditional operator
DEFINITION:
Theconditional operator (?:) evaluates a condition and returns one of two
values, depending on whether the condition is true or false.
Syntax
condition ? expression_if_true : expression_if_false;
21.
#include <stdio.h>
int main(){
int a = 10, b = 20;
int max;
max = (a > b) ? a : b;
printf("Maximum value is: %dn", max);
return 0;
}
Maximum value is: 20
Example program
Output
22.
PROJECT FOR C
LANGUAGE
#include<stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{
printf("%d is a Leap Year.n", year);
} else {
printf("%d is Not a Leap Year.n", year);
}
return 0;
}
Enter a year: 4000
4000 is a Leap Year.
Program
Output