SlideShare a Scribd company logo
PROGRAMMING
C
UNIT-1
Fundamentals of
computers:
What is a Computer?
A computer is an electronic device capable of performing calculations, processing data, and following
instructions with incredible speed and accuracy. It's essentially a tool that manipulates information under
the control of programs.
Basic Functions of a Computer
1.Input
2.Processing
3.Output
4.Storage
Components of a
Computer
• Hardware
• Software
Types of Computers
• Personal Computers (PCs): Desktop and laptop computers for individual use.
• Mainframes: Large, powerful computers used by organizations for complex tasks.
• Supercomputers: Extremely fast computers used for scientific research and complex
calculations.
Computer Generations
Computers have evolved through several generations, each characterized by significant
technological advancements:
• First Generation: Vacuum tubes
• Second Generation: Transistors
• Third Generation: Integrated circuits
• Fourth Generation: Microprocessors
• Fifth Generation: Artificial intelligence
Classification of programming language
What is a programming language?
A programming language defines a set of instructions that are compiled together to perform a specific task
by the CPU (Central Processing Unit). The programming language mainly refers to high-level languages
such as C, C++, Pascal, Ada, COBOL, etc.
They can be classified into two categories:
• Low-level language
• High-level language
Problem Solving Techniques in Programming
Problem-solving is the core of programming. It involves breaking down a complex problem
into smaller, manageable sub-problems and then developing a logical solution. Here are some
fundamental techniques:
• Understanding the Problem
• Developing a Solution
• Implementing the Solution
• Common Problem-Solving Techniques
Over view of
C:
What is C?
• High-level, general-purpose programming language.
• Developed by Dennis Ritchie at Bell Labs in 1972.
• Known for efficiency, speed, and portability.
Characters are used in forming either words or numbers or even expressions in C
programming. Characters in C are classified into 4 groups
Character set in C:
• Letter(alphabets)
• Digit(numbers)
• Special character
• White Space(space)
Tokens in
C:
A token in C can be defined as the smallest individual element of the C programming
language that is meaningful to the compiler. It is the basic component of a C program.
Types of Tokens in
C: 1.Keywords
2.Identifiers
3.Constants
4.Strings
5.Special Symbols
6.Operators
Keyword &
Identifiers:
Keywords: Predefined reserved words with specific meanings in a programming language,
used to define its syntax structure.
Example: int, float, char, if, else, for, while, return.
Identifiers: User-defined names given to program elements like variables, functions, or data
types for identification.
Example: age, name, total, calculate_area, my_variable.
Constant in C:
Constants in C are fixed values that cannot be modified once assigned. They are used to
represent values that remain constant throughout the program.
Syntax:
const data_type constant_name = value;
Variables are essentially named storage locations in a computer's memory used to hold data
values that can be changed during program execution. Think of them as containers that can
store different values of a specific data type.
Variables in
C:
Syntax:
data_type variable_name;
Datatype in
C:
A data type in C specifies the kind of data a variable can hold and the operations that can be
performed on it. It determines how the data is stored in memory and interpreted by the
compiler.
Declaration of
variables:
Variable declaration is the process of informing the compiler about the name and data type of
a variable before using it in a program. This allows the compiler to allocate appropriate
memory space for the variable.
Syntax:
data_type variable_name;
Example for Declaration:
int age;
float height;
char initial;
Assigning values to
variables:
Assigning a value to a variable in C means storing a specific data item in the memory
location represented by that variable. This is done using the assignment operator (=).
Syntax:
variable_name = value;
Example:
int age = 25;
float height = 1.75;
char initial = 'A';
Defining Symbolic
Constants:
A symbolic constant is a name given to a fixed value that cannot be changed during program
execution. It improves code readability and maintainability. There are two primary methods
to define symbolic constants in C:
1. Using the “#define” Preprocessor Directive
The #define directive is used to replace a symbolic name with a constant value during the
preprocessing stage.
Syntax:
#define CONSTANT_NAME value
2. Using the const Keyword
The const keyword declares a read-only variable, which essentially acts as a constant.
Syntax:
const data_type CONSTANT_NAME = value;
Types of Operators in C
Operators are symbols that perform specific operations on one or more operands. C offers a
variety of operators to manipulate data effectively.
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Increment and Decrement Operators
• Conditional Operator
• Special
Arithmetic
Operator:
Arithmetic Operators
Arithmetic operators are used to perform mathematical calculations on numerical values.
List of Arithmetic Operators:
• + : Addition
• - : Subtraction
• * : Multiplication
• / : Division
• % : Modulus (remainder)
Example:
int a = 10, b = 3;
int sum = a + b;
int difference = a - b;
int quotient = a / b;
Relational
Operator:
Relational operators compare two operands and return a boolean value (true or false).
List of Relational Operators:
• < : Less than
• > : Greater than
• <= : Less than or equal to
• >= : Greater than or equal to
• == : Equal to
• != : Not equal to
Example:
int a = 10, b = 5;
bool isGreater = a > b;
bool isEqual = a == b;
Logical
Operator:
Logical Operators
Logical operators combine boolean expressions.
List of Logical Operators:
• && : Logical AND
• || : Logical OR
• ! : Logical NOT
Example:
bool isEven = (num % 2) == 0;
bool isPositive = num > 0;
bool isEvenPositive = isEven && isPositive;
bool isEvenOrPositive = isEven || isPositive;
bool isNotEven = !isEven;
Assignment Operators:
Assignment operators are used to assign values to variables.
List of Assignment Operators:
• = : Simple assignment (assigns the right-hand value to the left-hand variable)
• += : Add and assign (adds the right-hand value to the left-hand variable and assigns the
result back to the left-hand variable)
• -= : Subtract and assign
• *= : Multiply and assign
• / : Divide and assign
• %= : Modulus and assign
Example:
int x = 10;
x += 5;
Conditional Operator (Ternary Operator):
The conditional operator is a shorthand for an if-else statement.
Example:
int max;
if (a > b) {
max = a;
}
else {
max = b;
}
Bitwise operators operate on individual bits of their operands.
List of Bitwise Operators:
• & : Bitwise AND
• | : Bitwise OR
• ^ : Bitwise XOR
• ~ : Bitwise complement (unary)
• << : Left shift
• >> : Right shift
Example:
int x = 5, y = 3;
int result1 = x & y;
int result2 = x | y;
int result3 = x ^ y;
int result4 = ~x; //
int result5 = x << 2;
int result6 = x >> 1;
Bitwise
Operator:
Special
Operator:
• sizeof : Returns the size of a data type or variable in bytes.
• comma : Separates expressions in a statement.
Example:
int sizeOfInt = sizeof(int);
int a = (5, 6);
Increment and Decrement
Operator:
These operators are used to increase or decrease the value of a variable by
1.
Types:
• Prefix increment (++): Increments the value of the variable before
using it in the expression.
• Postfix increment (++): Increments the value of the variable after using
it in the expression.
• Prefix decrement (--): Decrements the value of the variable before using it in the
expression.
• Postfix decrement (--): Decrements the value of the variable after using it in the
expression.
Example:
int x = 5;
int y = ++x;
int z = x++;
int a = --x;
int b = x--;
Arithmetic
Expressions:
Arithmetic Expressions in C
An arithmetic expression is a combination of operands (variables, constants, or function
calls) and arithmetic operators that evaluate to a numerical value.
Example:
int x = 10, y = 5;
int result = (x + y) * 2 - 3;
Evaluation of
Expressions:
Expression evaluation is the process of determining the value of an expression based on the values
of its operands and the operators involved.Order of Evaluation
The order in which operators are applied to operands is crucial for correct evaluation. It follows the
standard order of operations (PEMDAS/BODMAS):
1.Parentheses: Expressions within parentheses are evaluated first.
2.Exponents: Exponentiation is performed next.
3.Multiplication and Division: Performed from left to right.
4.Addition and Subtraction: Performed from left to right.
Complex Expressions:
For more complex expressions, use parentheses to explicitly define the order of evaluation:
int result = (5 + 3) * (2 - 4);
Procedure of Arithmetic
operator:
Procedure of Arithmetic Operators in C
Arithmetic operators perform basic mathematical operations on numerical values. The
process involved in their execution can be broken down into the following steps:
1.Operand Evaluation
2.Operator Identification
3. Data Type Conversion (if necessary)
4.Operation Execution
5.Result Assignment (if applicable)
C provides a rich set of mathematical functions to perform complex calculations. These
functions are primarily defined in the math.h header file.
Common Mathematical Functions
Here's a list of some commonly used mathematical functions:
• Trigonometric functions
• Exponential and logarithmic functions
• Rounding and absolute value functions
• Other functions
Mathematical
Function:
Example:
#include <stdio.h>
#include <math.h>
int main() {
double x = 3.14159;
double result;
result = sin(x); // Calculate sine of x
printf("sin(x) = %fn", result);
result = sqrt(16); // Calculate square root of 16
printf("sqrt(16) = %fn", result);
return 0;
}
Formatted input and
output:
Formatted input and output functions in C allow you to read and write data in a specific
format. The most commonly used functions for this purpose are printf() and scanf().
printf() Function
The printf() function is used to display formatted output on the console. It takes a format
string as its first argument, followed by optional arguments representing the values to be
printed.
Syntax:
printf(format_string, argument1, argument2, ...);
scanf() Function
The scanf() function is used to read formatted input from the console. It takes a format string
as its first argument, followed by pointers to variables where the input values will be stored.
Syntax:
scanf(format_string, &variable1, &variable2, ...);
Format Specifiers
• %d : Integer (signed decimal integer)
• %i : Integer (same as %d)
• %u : Unsigned integer (unsigned decimal integer)
• %ld : Long integer (signed long integer)
• %lu : Unsigned long integer (unsigned long integer)
• %lld : Long long integer (signed long long integer)
• %llu : Unsigned long long integer (unsigned long long integer)
• %f : Float (floating-point number)
• %lf : Double (double-precision floating-point number)
• %Lf : Long double (long double-precision floating-point number)
• %c : Character (single character)
• %s : String (null-terminated character array)
• %p : Pointer (pointer address)
• %x : Hexadecimal integer (lowercase)
• %X : Hexadecimal integer (uppercase)
• %o : Octal integer
THANK YOU

More Related Content

Similar to Fundamentals of computers - C Programming (20)

PPTX
#Code2 create c++ for beginners
GDGKuwaitGoogleDevel
 
PDF
CP c++ programing project Unit 1 intro.pdf
ShivamYadav886008
 
PPT
C material
tarique472
 
PDF
2 EPT 162 Lecture 2
Don Dooley
 
PDF
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
PDF
C intro
SHIKHA GAUTAM
 
PPTX
C programming
DipjualGiri1
 
PPTX
Unit No 2.pptx Basic s of C Programming
Vaibhav Parjane
 
PPT
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
PDF
c_programming.pdf
Home
 
PDF
C Programming Language Introduction and C Tokens.pdf
poongothai11
 
PPT
Ch2 introduction to c
Hattori Sidek
 
PPTX
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
PPTX
Shivani PPt C-programing-1.pptx
CodeHome
 
PPTX
C Language Part 1
Thapar Institute
 
PPSX
Programming in C [Module One]
Abhishek Sinha
 
PPTX
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
sanatahiratoz0to9
 
PPT
C language Unit 2 Slides, UPTU C language
Anurag University Hyderabad
 
PPTX
POLITEKNIK MALAYSIA
Aiman Hud
 
PPTX
Introduction to c
Ajeet Kumar
 
#Code2 create c++ for beginners
GDGKuwaitGoogleDevel
 
CP c++ programing project Unit 1 intro.pdf
ShivamYadav886008
 
C material
tarique472
 
2 EPT 162 Lecture 2
Don Dooley
 
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
C intro
SHIKHA GAUTAM
 
C programming
DipjualGiri1
 
Unit No 2.pptx Basic s of C Programming
Vaibhav Parjane
 
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
c_programming.pdf
Home
 
C Programming Language Introduction and C Tokens.pdf
poongothai11
 
Ch2 introduction to c
Hattori Sidek
 
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
Shivani PPt C-programing-1.pptx
CodeHome
 
C Language Part 1
Thapar Institute
 
Programming in C [Module One]
Abhishek Sinha
 
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
sanatahiratoz0to9
 
C language Unit 2 Slides, UPTU C language
Anurag University Hyderabad
 
POLITEKNIK MALAYSIA
Aiman Hud
 
Introduction to c
Ajeet Kumar
 

More from MSridhar18 (13)

PDF
Linked List - Part - 2 Linked List - Part - 2
MSridhar18
 
PDF
Singly Linked List - Singly Linked List - Part -1
MSridhar18
 
PDF
CONCEPT OF ARRAY IN DATA STRUCTURES CONCEPT OF ARRAY IN DATA STRUCTURES
MSridhar18
 
PDF
unit 1 ds.INTRODUCTION TO DATA STRUCTURES
MSridhar18
 
PPT
Data Warehouse Introduction to Data Warehouse
MSridhar18
 
PPT
Cluster Analysis K-Means Clustering Typically measured by Euclidean distance
MSridhar18
 
PPT
Classification and Cluster 2BCasic Concepts
MSridhar18
 
PPT
Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...
MSridhar18
 
PPT
Data Structures: A Foundation for Efficient Programming
MSridhar18
 
PPTX
ARRAY's in C Programming Language PPTX.
MSridhar18
 
PPTX
DECISION MAKING AND BRANCHING - C Programming
MSridhar18
 
PPTX
POINTERS AND FILE HANDLING - C Programming
MSridhar18
 
PPTX
USER DEFINE FUNCTION AND STRUCTURE AND UNION
MSridhar18
 
Linked List - Part - 2 Linked List - Part - 2
MSridhar18
 
Singly Linked List - Singly Linked List - Part -1
MSridhar18
 
CONCEPT OF ARRAY IN DATA STRUCTURES CONCEPT OF ARRAY IN DATA STRUCTURES
MSridhar18
 
unit 1 ds.INTRODUCTION TO DATA STRUCTURES
MSridhar18
 
Data Warehouse Introduction to Data Warehouse
MSridhar18
 
Cluster Analysis K-Means Clustering Typically measured by Euclidean distance
MSridhar18
 
Classification and Cluster 2BCasic Concepts
MSridhar18
 
Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...
MSridhar18
 
Data Structures: A Foundation for Efficient Programming
MSridhar18
 
ARRAY's in C Programming Language PPTX.
MSridhar18
 
DECISION MAKING AND BRANCHING - C Programming
MSridhar18
 
POINTERS AND FILE HANDLING - C Programming
MSridhar18
 
USER DEFINE FUNCTION AND STRUCTURE AND UNION
MSridhar18
 
Ad

Recently uploaded (20)

PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
infertility, types,causes, impact, and management
Ritu480198
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Introduction presentation of the patentbutler tool
MIPLM
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Difference between write and update in odoo 18
Celine George
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Controller Request and Response in Odoo18
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Ad

Fundamentals of computers - C Programming

  • 2. Fundamentals of computers: What is a Computer? A computer is an electronic device capable of performing calculations, processing data, and following instructions with incredible speed and accuracy. It's essentially a tool that manipulates information under the control of programs. Basic Functions of a Computer 1.Input 2.Processing 3.Output 4.Storage
  • 3. Components of a Computer • Hardware • Software Types of Computers • Personal Computers (PCs): Desktop and laptop computers for individual use. • Mainframes: Large, powerful computers used by organizations for complex tasks. • Supercomputers: Extremely fast computers used for scientific research and complex calculations.
  • 4. Computer Generations Computers have evolved through several generations, each characterized by significant technological advancements: • First Generation: Vacuum tubes • Second Generation: Transistors • Third Generation: Integrated circuits • Fourth Generation: Microprocessors • Fifth Generation: Artificial intelligence
  • 5. Classification of programming language What is a programming language? A programming language defines a set of instructions that are compiled together to perform a specific task by the CPU (Central Processing Unit). The programming language mainly refers to high-level languages such as C, C++, Pascal, Ada, COBOL, etc. They can be classified into two categories: • Low-level language • High-level language
  • 6. Problem Solving Techniques in Programming Problem-solving is the core of programming. It involves breaking down a complex problem into smaller, manageable sub-problems and then developing a logical solution. Here are some fundamental techniques: • Understanding the Problem • Developing a Solution • Implementing the Solution • Common Problem-Solving Techniques
  • 7. Over view of C: What is C? • High-level, general-purpose programming language. • Developed by Dennis Ritchie at Bell Labs in 1972. • Known for efficiency, speed, and portability. Characters are used in forming either words or numbers or even expressions in C programming. Characters in C are classified into 4 groups Character set in C: • Letter(alphabets) • Digit(numbers) • Special character • White Space(space)
  • 8. Tokens in C: A token in C can be defined as the smallest individual element of the C programming language that is meaningful to the compiler. It is the basic component of a C program. Types of Tokens in C: 1.Keywords 2.Identifiers 3.Constants 4.Strings 5.Special Symbols 6.Operators
  • 9. Keyword & Identifiers: Keywords: Predefined reserved words with specific meanings in a programming language, used to define its syntax structure. Example: int, float, char, if, else, for, while, return. Identifiers: User-defined names given to program elements like variables, functions, or data types for identification. Example: age, name, total, calculate_area, my_variable.
  • 10. Constant in C: Constants in C are fixed values that cannot be modified once assigned. They are used to represent values that remain constant throughout the program. Syntax: const data_type constant_name = value; Variables are essentially named storage locations in a computer's memory used to hold data values that can be changed during program execution. Think of them as containers that can store different values of a specific data type. Variables in C: Syntax: data_type variable_name;
  • 11. Datatype in C: A data type in C specifies the kind of data a variable can hold and the operations that can be performed on it. It determines how the data is stored in memory and interpreted by the compiler.
  • 12. Declaration of variables: Variable declaration is the process of informing the compiler about the name and data type of a variable before using it in a program. This allows the compiler to allocate appropriate memory space for the variable. Syntax: data_type variable_name; Example for Declaration: int age; float height; char initial;
  • 13. Assigning values to variables: Assigning a value to a variable in C means storing a specific data item in the memory location represented by that variable. This is done using the assignment operator (=). Syntax: variable_name = value; Example: int age = 25; float height = 1.75; char initial = 'A';
  • 14. Defining Symbolic Constants: A symbolic constant is a name given to a fixed value that cannot be changed during program execution. It improves code readability and maintainability. There are two primary methods to define symbolic constants in C: 1. Using the “#define” Preprocessor Directive The #define directive is used to replace a symbolic name with a constant value during the preprocessing stage. Syntax: #define CONSTANT_NAME value
  • 15. 2. Using the const Keyword The const keyword declares a read-only variable, which essentially acts as a constant. Syntax: const data_type CONSTANT_NAME = value; Types of Operators in C Operators are symbols that perform specific operations on one or more operands. C offers a variety of operators to manipulate data effectively. • Arithmetic Operators • Relational Operators • Logical Operators • Bitwise Operators • Assignment Operators • Increment and Decrement Operators • Conditional Operator • Special
  • 16. Arithmetic Operator: Arithmetic Operators Arithmetic operators are used to perform mathematical calculations on numerical values. List of Arithmetic Operators: • + : Addition • - : Subtraction • * : Multiplication • / : Division • % : Modulus (remainder) Example: int a = 10, b = 3; int sum = a + b; int difference = a - b; int quotient = a / b;
  • 17. Relational Operator: Relational operators compare two operands and return a boolean value (true or false). List of Relational Operators: • < : Less than • > : Greater than • <= : Less than or equal to • >= : Greater than or equal to • == : Equal to • != : Not equal to Example: int a = 10, b = 5; bool isGreater = a > b; bool isEqual = a == b;
  • 18. Logical Operator: Logical Operators Logical operators combine boolean expressions. List of Logical Operators: • && : Logical AND • || : Logical OR • ! : Logical NOT Example: bool isEven = (num % 2) == 0; bool isPositive = num > 0; bool isEvenPositive = isEven && isPositive; bool isEvenOrPositive = isEven || isPositive; bool isNotEven = !isEven;
  • 19. Assignment Operators: Assignment operators are used to assign values to variables. List of Assignment Operators: • = : Simple assignment (assigns the right-hand value to the left-hand variable) • += : Add and assign (adds the right-hand value to the left-hand variable and assigns the result back to the left-hand variable) • -= : Subtract and assign • *= : Multiply and assign • / : Divide and assign • %= : Modulus and assign Example: int x = 10; x += 5;
  • 20. Conditional Operator (Ternary Operator): The conditional operator is a shorthand for an if-else statement. Example: int max; if (a > b) { max = a; } else { max = b; }
  • 21. Bitwise operators operate on individual bits of their operands. List of Bitwise Operators: • & : Bitwise AND • | : Bitwise OR • ^ : Bitwise XOR • ~ : Bitwise complement (unary) • << : Left shift • >> : Right shift Example: int x = 5, y = 3; int result1 = x & y; int result2 = x | y; int result3 = x ^ y; int result4 = ~x; // int result5 = x << 2; int result6 = x >> 1; Bitwise Operator:
  • 22. Special Operator: • sizeof : Returns the size of a data type or variable in bytes. • comma : Separates expressions in a statement. Example: int sizeOfInt = sizeof(int); int a = (5, 6); Increment and Decrement Operator: These operators are used to increase or decrease the value of a variable by 1. Types: • Prefix increment (++): Increments the value of the variable before using it in the expression. • Postfix increment (++): Increments the value of the variable after using it in the expression.
  • 23. • Prefix decrement (--): Decrements the value of the variable before using it in the expression. • Postfix decrement (--): Decrements the value of the variable after using it in the expression. Example: int x = 5; int y = ++x; int z = x++; int a = --x; int b = x--;
  • 24. Arithmetic Expressions: Arithmetic Expressions in C An arithmetic expression is a combination of operands (variables, constants, or function calls) and arithmetic operators that evaluate to a numerical value. Example: int x = 10, y = 5; int result = (x + y) * 2 - 3;
  • 25. Evaluation of Expressions: Expression evaluation is the process of determining the value of an expression based on the values of its operands and the operators involved.Order of Evaluation The order in which operators are applied to operands is crucial for correct evaluation. It follows the standard order of operations (PEMDAS/BODMAS): 1.Parentheses: Expressions within parentheses are evaluated first. 2.Exponents: Exponentiation is performed next. 3.Multiplication and Division: Performed from left to right. 4.Addition and Subtraction: Performed from left to right. Complex Expressions: For more complex expressions, use parentheses to explicitly define the order of evaluation: int result = (5 + 3) * (2 - 4);
  • 26. Procedure of Arithmetic operator: Procedure of Arithmetic Operators in C Arithmetic operators perform basic mathematical operations on numerical values. The process involved in their execution can be broken down into the following steps: 1.Operand Evaluation 2.Operator Identification 3. Data Type Conversion (if necessary) 4.Operation Execution 5.Result Assignment (if applicable)
  • 27. C provides a rich set of mathematical functions to perform complex calculations. These functions are primarily defined in the math.h header file. Common Mathematical Functions Here's a list of some commonly used mathematical functions: • Trigonometric functions • Exponential and logarithmic functions • Rounding and absolute value functions • Other functions Mathematical Function: Example: #include <stdio.h> #include <math.h> int main() { double x = 3.14159; double result; result = sin(x); // Calculate sine of x printf("sin(x) = %fn", result); result = sqrt(16); // Calculate square root of 16 printf("sqrt(16) = %fn", result); return 0; }
  • 28. Formatted input and output: Formatted input and output functions in C allow you to read and write data in a specific format. The most commonly used functions for this purpose are printf() and scanf(). printf() Function The printf() function is used to display formatted output on the console. It takes a format string as its first argument, followed by optional arguments representing the values to be printed. Syntax: printf(format_string, argument1, argument2, ...);
  • 29. scanf() Function The scanf() function is used to read formatted input from the console. It takes a format string as its first argument, followed by pointers to variables where the input values will be stored. Syntax: scanf(format_string, &variable1, &variable2, ...); Format Specifiers • %d : Integer (signed decimal integer) • %i : Integer (same as %d) • %u : Unsigned integer (unsigned decimal integer) • %ld : Long integer (signed long integer) • %lu : Unsigned long integer (unsigned long integer) • %lld : Long long integer (signed long long integer)
  • 30. • %llu : Unsigned long long integer (unsigned long long integer) • %f : Float (floating-point number) • %lf : Double (double-precision floating-point number) • %Lf : Long double (long double-precision floating-point number) • %c : Character (single character) • %s : String (null-terminated character array) • %p : Pointer (pointer address) • %x : Hexadecimal integer (lowercase) • %X : Hexadecimal integer (uppercase) • %o : Octal integer