SlideShare a Scribd company logo
1 of 96
INTRODUCTION TO C
BASIC STRUCTURE OF A C PROGRAM
Main sections to a basic C program.
 Documentation
 Link
 Definition
 Global Declarations
 Main functions
 Subprograms
INTRODUCTION TO C
BASIC STRUCTURE OF A C PROGRAM
INTRODUCTION TO C
BASIC STRUCTURE OF A C PROGRAM
Documentation Section
He usually gives the name of the program, the details of the author and
other details. It gives anyone reading the code the overview of the code.
Link Section
This part of the code is used to declare all the header files that will be
used in the program. This leads to the compiler being told to link the
header files to the system libraries.
INTRODUCTION TO C
BASIC STRUCTURE OF A C PROGRAM
Definition Section
we define different constants. The keyword define is used in this part.
Global Declaration Section
This part of the code is the part where the global variables are declared.
All the global variable used are declared in this part. The user-defined
functions are also declared in this part of the code.
INTRODUCTION TO C
BASIC STRUCTURE OF A C PROGRAM
Main Function Section
Every C-programs needs to have the main function.
Each main function contains 2 parts.
 Declaration part
 Execution part.
Both the declaration and execution part are inside the curly
braces.
INTRODUCTION TO C
BASIC STRUCTURE OF A C PROGRAM
Sub Program Section
All the user-defined functions are defined in this section of the
program.
INTRODUCTION TO C
FUNDAMENTAL CHARACTER SET
Set of all valid character which is used to form a words, numbers and
expression’s in source program.
Type of C character set
 Alphabets
 Digit
 Special Character
 White space
INTRODUCTION TO C
IDENTIFIERS
Identifiers are user-defined names of variables, functions and arrays.
It comprises of combination of letters and digits.
 It must begin with an alphabet or an underscore and not digits.
 It must contain only alphabets, digits or underscore.
 A keyword cannot be used as an identifier
 Must not contain white space.
INTRODUCTION TO C
KEYWORDS
Keywords are special words in C programming which have their own
predefined meaning.
The functions and meanings of these words cannot be altered.
INTRODUCTION TO C
KEYWORDS
auto break case char
continue const do default
double else enum extern
for float go if
int long register return
sign static sizeof short
struct switch typedef union
void volatile while unsigned
INTRODUCTION TO C
DATA TYPES
Refers to the type of data used to store the information.
Four different data types can be used to differentiate and store
various types of data.
INTRODUCTION TO C
DATA TYPES
Type Data types
Basic data types int, char, float, & double
Derived data types array, pointer, structure, & union
Enumeration data type enum
Void data type void
INTRODUCTION TO C
CONSTANT
The value which cannot be modified during the execution of the program.
Constant for representing the fixed values which do not change.
Types of Constants
 Integer Constants
 Floating Point Constants
 Character Constants
 String Constants
 Enumeration Constants
INTRODUCTION TO C
VARIABLES
A variable is a container (storage area) to hold data.
To indicate the storage area, each variable should be given a unique
name (identifier).
Variable names are just the symbolic representation of a memory
location.
INTRODUCTION TO C
VARIABLES
Syntax
Data-type Variabl name;
INTRODUCTION TO C
EXPRESSION
Expressions are the combination of variables, operands, and operators.
Types of Expressions in C
 Arithmetic expressions
 Relational expressions
 Logical expressions
 Conditional expressions
INTRODUCTION TO C
STATEMENTS
Statements is an executable part of the program it will do some
action.
 Expression Statements
 Compound Statements
 Selection Statements
 Iterative Statements
 Jump Statements
INTRODUCTION TO C
OPERATORS
Operators take part in a program for manipulating data and variables
and form a part of the mathematical, conditional, or logical
expressions.
INTRODUCTION TO C
OPERATORS
Types of Operators
 Arithmetic Operator
 Assignment Operator
 Relational Operator
 Logical Operator
 Bitwise Operator
INTRODUCTION TO C
LIBRARY FUNCTIONS
Library functions or simply C Library functions are inbuilt functions in
C programming.
The prototype and data definitions of these functions are present in
their respective header files. To use these functions we need to
include the header file in our program.
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
DATA INPUT OUTPUT FUNCTIONS
 Accepting of data as input
 The processing of data
 The generation of output
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
DATA INPUT OUTPUT FUNCTIONS
Types of Input and Output functions
 Unformatted Data input and output functions
 Formatted Data input and output functions
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
DATA INPUT OUTPUT FUNCTIONS
Unformatted Data input and output functions
The unformatted functions are not capable of controlling the format
that is involved in writing and reading the available data.
 getchar() & putchar() functions
 gets() & puts() functions
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
DATA INPUT OUTPUT FUNCTIONS
Formatted Data input and output functions
 printf( )
 scnanf( )
The formatted functions basically present or accept the available
data (input) in a specific format.
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
DATA INPUT OUTPUT FUNCTIONS
printf( ) function
printf() is formatted output function which is used to display some
information on standard output unit.
Syntax
printf(“format_specifies”, var1, var2, var3, …, varN);
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
DATA INPUT OUTPUT FUNCTIONS
scanf( ) function
scanf() is formatted input function which is used to read formatted
data from standard input device and automatically converts numeric
information to integers and floats. It is defined in stdio.h.
Syntax
scanf(“format_string”, &var1, &var2, &var3, …, &varN);
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
SIMPLE C PROGRAMS
#include <stdio.h>
void main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
printf("You entered: %d", number);
}
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
FLOW OF CONTROL
A special statement to control the execution of one or more statements
depending on a condition. Such statements are called control statements
or control-flow statements.
Types of control-flow statements
 Selection Statement
 Iterative Statement
 Unconditional Control Statement
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
Selection Statement
It is a statement whose execution results in a choice being made as
to which of two or more paths should be followed.
 if construct
 if-else construct
 if-else-if construct
 Nested if-else-if construct
 switch-case construct
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
IF STATEMENT
The if construct is a selective statement, the statements within the
block are executed only once when the condition evaluates to true,
otherwise the control goes to the first statement after the if
construct.
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
IF STATEMENT
The general form
if (condition)
{
statement-1;
statement-2;
....
statement-n;
}
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
IF STATEMENT
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
IF-ELSE STATEMENT
An if statement will execute its block only when the condition
evaluates to 1 (true).
We can also conditionally execute another block when the condition
evaluates to 0 (false) using the else construct.
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
IF-ELSE STATEMENT
The general syntax
if (expression)
{
statement-1;
}
else
{
statement-2;
}
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
IF-ELSE STATEMENT
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
IF-ELSE-IF STATEMENT
Multiple if constructs can be chained to any length. The else
construct which appears at the end is optional, and if it is to be
included it has to be only at the end.
The if-else-if construct is used whenever we have multiple mutually
exclusive if conditions that work on the same input.
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
IF-ELSE-IF STATEMENT
General form
if (expression_1) {
statement_1;
} else if (expression_2) {
statement_2;
} else if (expression_3) {
statement_3;
} else if (expression_4) {
statement_4;
} else {
statement_5;
}
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
The process of repeatedly executing a statement or group of
statements until the condition is satisfied is called looping.
 While loop
 Do..while loop
 for loop
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
WHILE LOOP
To evaluate a test condition and iterate over the loop body until the
condition returns True. The loop ends when the condition returns
False.
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
while (condition)
{
body of while loop
}
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
DO….WHILE LOOP
The body is executed if and only if the condition is true. In some
cases, we have to execute a body of the loop at least once even if the
condition is false.
This type of operation can be achieved by using a do-while loop.
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
DO….WHILE LOOP
do {
statements
} while (expression);
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
FOR LOOP
The initial value of the for loop is performed only once.
The condition is a Boolean expression that tests and compares the
counter to a fixed value after each iteration, stopping the for loop when
false is returned.
The incrementation/decrementation increases (or decreases) the counter
by a set value.
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
FOR LOOP
Syntax
for (initial value; condition; incrementation or decrementation )
{
statements;
}
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
LOOP STATEMENT
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
SWITCH
The switch statement allows us to execute one code block among
many alternatives.
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
switch (expression)
{
case constant1:
// statements
break;
case constant2:
// statements
break;
.
.
.
default:
// default statements
}
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
BREAK AND CONTINUE
Break
The break statement ends the loop immediately when it is
encountered.
syntax
break;
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
BREAK AND CONTINUE
Continue
The continue statement skips the current iteration of the loop and
continues with the next iteration.
Syntax
continue;
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
GO - TO STATEMENTS
The goto statement allows us to transfer control of the program to the
specified label.
Syntax
goto label;
... .. ...
... .. ...
label:
statement;
INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
COMMA OPERATOR
The comma operator in C is denoted by ,. The comma operator in C
has the least precedence.
The comma operator in C ensures that two or more expressions
separated by commas are evaluated one by one from left to right,
and the result of the entire expression is the value of the rightmost
expression.
FUNCTIONS
Definition
A function is a block of code that performs a specific task.
Benefits of functions
Enables reusability and reduces redundancy
Makes a code modular
Provides abstraction functionality
The program becomes easy to understand and manage
Breaks an extensive program into smaller and simpler pieces
FUNCTIONS
Basic Syntax of Functions
return_type function_name(arg1, arg2, … argn)
{
Body of the function //Statements to be processed
}
FUNCTIONS
FUNCTION PROTO-TYPES
A function prototype is a declaration in the code that instructs the compiler
about the data type of the function, arguments and parameter list. As we all
know that a block of code which performs a specific task is called as a
function.
FUNCTIONS
Syntax
returntypefunctionname(datatype paramter1 , datatype paramter2 ,
datatype paramter3..);
FUNCTIONS
PASSING ARGUMENTS
C programming function arguments also known as parameters are the
variables that will receive the data sent by the calling program. These
arguments serve as input data to the function to carry out the specified
task.
FUNCTIONS
PASSING ARGUMENTS
FUNCTIONS
Function arguments in c programming
Basically, there are two types of arguments:
Actual arguments
Formal arguments
FUNCTIONS
Function arguments in c programming
Two ways to pass arguments to the function
Pass by Value
Pass by value is a method in which a copy of the value of the variables is
passed to the function for the specific operation.
Pass by reference
Pass by reference is a method in which rather than passing direct value the
address of the variable is passed as an argument to the called function.
FUNCTIONS
RECURSIONS
A function that calls itself is known as a recursive function. And, this technique is known as recursion.
void recurse()
{
... .. ...
recurse();
... .. ...
}
int main()
{
... .. ...
recurse();
... .. ...
}
FUNCTIONS
STORAGE CLASSES
The variable scope.
The location where the variable will be stored.
The initialized value of a variable.
A lifetime of a variable.
FUNCTIONS
There are 4 types of storage class
 automatic
 external
 static
 register
FUNCTIONS
MULTIFILE PROGRAMS
If a program contains many functions then it is difficult to read and
maintain because when the number of functions increases the size of the
program/file will also increase. To avoid this some functions can be written
in separate file
The individual files will be compiled separately and then linked together to
form one executable object program.
FUNCTIONS
MULTIFILE PROGRAMS
If a program contains many functions then it is difficult to read and
maintain because when the number of functions increases the size of the
program/file will also increase. To avoid this some functions can be written
in separate file
The individual files will be compiled separately and then linked together to
form one executable object program.
ARRAYS
An array is a collection of variables of same data types.
Advantage of Arrays
Less amount of code :
Easy access of elements :
Easy to implement algorithms :
Random Access :
ARRAYS
Declare an array
dataType arrayName[arraySize];
Example
float mark[5];
ARRAYS
Types of Array
1. Single dimensional arrays
2. Multidimensional arrays
ARRAYS
Single dimensional arrays
Single dimensional array or 1-D array is the simplest form of
arrays that can be found in C. This type of array consists of
elements of similar types and these elements can be accessed
through their indices.
ARRAYS
Multi-dimensional Arrays
The most common type of multi-dimensional array that is used in
the C language is a 2-D array. However, the number of dimensions
can be more than 2 depending upon the compiler of the user’s
system. These arrays consist of elements that are array
themselves.
ARRAYS
Multi-dimensional Arrays
PASSING ARRAYS TO FUNCTIONS
An array is a collection of similar data types which are stored in
memory as a contiguous memory block.
This means multi-dimensional arrays are also a continuous block
of data in our memory. In C, there are several times when we are
required to pass an array to a function argument.
ARRAYS AND STRING
A string is a sequence of characters terminated with a null
character.
Example
char c[] = "c string";
STRUCTURES
A struct (or structure) is a collection of variables (can be of
different types) under a single name.
To define a struct, the struct keyword is used.
STRUCTURES
Syntax of struct
struct structureName
{
dataType member1;
dataType member2;
...
};
USER DEFINED DATA TYPES
 Structure
 Union
 Enumeration
USER DEFINED DATA TYPES
Union
A union is also a user-defined data type. It also holds members of
different data types under a single name. A union sounds similar
to a structure and they are similar in conceptual terms. But there
are some major differences between the two.
While a structure allocates sufficient memory for all its members,
a union only allocates memory equal to its largest member.
USER DEFINED DATA TYPES
Union
Syntax
union union_name
{
data_type var1;
data_type var2;
};
USER DEFINED DATA TYPES
Enumeration
Enumeration or simply enum is one of the user-defined data types
in C which provides a special type of flexibility of defining
variables. An enum consists of a set of integer constants that can
be replaced by user-defined names.
Syntax
enum flag {const_name1, const_name2, ..., const_nameN};
PASSING STRUCTURES TO FUNCTIONS
A structure can be passed to any function from main function or
from any sub function.
Structure definition will be available within the function only.
It won’t be available to other functions unless it is passed to those
functions by value or by address(reference).
PASSING STRUCTURES TO FUNCTIONS
Passing structure to function
It can be done in below 3 ways.
1. Passing structure to a function by value
2. Passing structure to a function by address(reference)
3. No need to pass a structure – Declare structure variable as
global
SELF-REFERENTIAL STRUCTURES
A self-referential structure is a structure that contains a pointer to
a variable of the same type. This allows the structure to refer to
itself, creating a linked data structure.
The concept of a self-referential structure is based on the idea of a
linked list, which is a collection of data elements that are
connected to each other through a series of pointers.
BITWISE OPERATIONS
In the arithmetic-logic unit (which is within the CPU),
mathematical operations like: addition, subtraction,
multiplication and division are done in bit-level. To perform bit-
level operations in C programming, bitwise operators are used.
POINTERS
A Pointer is a variable that holds the memory address of another
variable.
POINTER DECLARATION
datatype *pointer_variableName;
Example
int *ptr;
POINTERS
A Pointer is a variable that holds the memory address of another
variable.
POINTER DECLARATION
datatype *pointer_variableName;
Example
int *ptr;
PASSING POINTERS TO FUNCTIONS
Pointers can also be passed as an argument to a function like any
other argument. Instead of a variable.
Declare a function which accepts a pointer as an argument
return_type function_name(int*);
OPERATION IN POINTERS
An address in a memory is a numeric value we can perform
arithmetic operations on the pointer values.
Different operations
Assignment
Value finding
Taking a pointer address
Incrementing and Decrement a pointer
POINTER AND ARRAYS
Pointers and Array representations are very much related to each
other and can be interchangeably used in the right context.
Arrays can be single or multidimensional and are stored in contiguous
memory blocks in our system.
ARRAYS AND POINTERS
Pointer
Address of a variable in memory.
Allows us to indirectly access variables.
Arrays
Array is a group of elements that share a common name, and that are
different from one another by their positions within the array.
ARRAYS AND POINTERS
STRUCTURES AND POINTERS
Structure pointer points to the address of the structure variable in
the memory block to which it points.
This pointer can be used to access and change the value of structure
members.
STRUCTURES AND POINTERS
struct name {
member1;
member2;
.
.
};
int main()
{
struct name *ptr, Harry;
}
FILES
A file represents a sequence of bytes on the disk where a group of
related data is stored. File is created for permanent storage of data. It
is a ready made structure.
A file is a container in computer storage devices used for storing data.
FILES
Basic file operations
Function Description
fopen() create a new file or open a existing file
fclose() closes a file
getc() reads a character from a file
putc() writes a character to a file
fscanf() reads a set of data from a file
fprintf() writes a set of data to a file
getw() reads a integer from a file
putw() writes a integer to a file
fseek() set the position to desire point
ftell() gives current position in the file
rewind() set the position to the begining point

More Related Content

Similar to Programming-in-C

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
Unit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptxUnit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptxPragatheshP
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptxmadhurij54
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
 
Chapter3
Chapter3Chapter3
Chapter3Kamran
 
c_programming.pdf
c_programming.pdfc_programming.pdf
c_programming.pdfHome
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 

Similar to Programming-in-C (20)

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Unit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptxUnit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptx
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
C
CC
C
 
C intro
C introC intro
C intro
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
Chapter3
Chapter3Chapter3
Chapter3
 
c_programming.pdf
c_programming.pdfc_programming.pdf
c_programming.pdf
 
C programming language
C programming languageC programming language
C programming language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 

More from DrPrabakaranPerumal (10)

AdvancedJava.pptx
AdvancedJava.pptxAdvancedJava.pptx
AdvancedJava.pptx
 
Java.pptx
Java.pptxJava.pptx
Java.pptx
 
IoT.pptx
IoT.pptxIoT.pptx
IoT.pptx
 
EthicalHacking.pptx
EthicalHacking.pptxEthicalHacking.pptx
EthicalHacking.pptx
 
SoftwareEngineering.pptx
SoftwareEngineering.pptxSoftwareEngineering.pptx
SoftwareEngineering.pptx
 
SoftwareTesting.pptx
SoftwareTesting.pptxSoftwareTesting.pptx
SoftwareTesting.pptx
 
Html-Prabakaran
Html-PrabakaranHtml-Prabakaran
Html-Prabakaran
 
VOSUnit
VOSUnitVOSUnit
VOSUnit
 
OpeatingSystemPPT
OpeatingSystemPPTOpeatingSystemPPT
OpeatingSystemPPT
 
JavaAdvUnit-1.pptx
JavaAdvUnit-1.pptxJavaAdvUnit-1.pptx
JavaAdvUnit-1.pptx
 

Recently uploaded

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

Programming-in-C

  • 1. INTRODUCTION TO C BASIC STRUCTURE OF A C PROGRAM Main sections to a basic C program.  Documentation  Link  Definition  Global Declarations  Main functions  Subprograms
  • 2. INTRODUCTION TO C BASIC STRUCTURE OF A C PROGRAM
  • 3. INTRODUCTION TO C BASIC STRUCTURE OF A C PROGRAM Documentation Section He usually gives the name of the program, the details of the author and other details. It gives anyone reading the code the overview of the code. Link Section This part of the code is used to declare all the header files that will be used in the program. This leads to the compiler being told to link the header files to the system libraries.
  • 4. INTRODUCTION TO C BASIC STRUCTURE OF A C PROGRAM Definition Section we define different constants. The keyword define is used in this part. Global Declaration Section This part of the code is the part where the global variables are declared. All the global variable used are declared in this part. The user-defined functions are also declared in this part of the code.
  • 5. INTRODUCTION TO C BASIC STRUCTURE OF A C PROGRAM Main Function Section Every C-programs needs to have the main function. Each main function contains 2 parts.  Declaration part  Execution part. Both the declaration and execution part are inside the curly braces.
  • 6. INTRODUCTION TO C BASIC STRUCTURE OF A C PROGRAM Sub Program Section All the user-defined functions are defined in this section of the program.
  • 7. INTRODUCTION TO C FUNDAMENTAL CHARACTER SET Set of all valid character which is used to form a words, numbers and expression’s in source program. Type of C character set  Alphabets  Digit  Special Character  White space
  • 8. INTRODUCTION TO C IDENTIFIERS Identifiers are user-defined names of variables, functions and arrays. It comprises of combination of letters and digits.  It must begin with an alphabet or an underscore and not digits.  It must contain only alphabets, digits or underscore.  A keyword cannot be used as an identifier  Must not contain white space.
  • 9. INTRODUCTION TO C KEYWORDS Keywords are special words in C programming which have their own predefined meaning. The functions and meanings of these words cannot be altered.
  • 10. INTRODUCTION TO C KEYWORDS auto break case char continue const do default double else enum extern for float go if int long register return sign static sizeof short struct switch typedef union void volatile while unsigned
  • 11. INTRODUCTION TO C DATA TYPES Refers to the type of data used to store the information. Four different data types can be used to differentiate and store various types of data.
  • 12. INTRODUCTION TO C DATA TYPES Type Data types Basic data types int, char, float, & double Derived data types array, pointer, structure, & union Enumeration data type enum Void data type void
  • 13. INTRODUCTION TO C CONSTANT The value which cannot be modified during the execution of the program. Constant for representing the fixed values which do not change. Types of Constants  Integer Constants  Floating Point Constants  Character Constants  String Constants  Enumeration Constants
  • 14. INTRODUCTION TO C VARIABLES A variable is a container (storage area) to hold data. To indicate the storage area, each variable should be given a unique name (identifier). Variable names are just the symbolic representation of a memory location.
  • 16. INTRODUCTION TO C EXPRESSION Expressions are the combination of variables, operands, and operators. Types of Expressions in C  Arithmetic expressions  Relational expressions  Logical expressions  Conditional expressions
  • 17. INTRODUCTION TO C STATEMENTS Statements is an executable part of the program it will do some action.  Expression Statements  Compound Statements  Selection Statements  Iterative Statements  Jump Statements
  • 18. INTRODUCTION TO C OPERATORS Operators take part in a program for manipulating data and variables and form a part of the mathematical, conditional, or logical expressions.
  • 19. INTRODUCTION TO C OPERATORS Types of Operators  Arithmetic Operator  Assignment Operator  Relational Operator  Logical Operator  Bitwise Operator
  • 20. INTRODUCTION TO C LIBRARY FUNCTIONS Library functions or simply C Library functions are inbuilt functions in C programming. The prototype and data definitions of these functions are present in their respective header files. To use these functions we need to include the header file in our program.
  • 21. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES DATA INPUT OUTPUT FUNCTIONS  Accepting of data as input  The processing of data  The generation of output
  • 22. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES DATA INPUT OUTPUT FUNCTIONS Types of Input and Output functions  Unformatted Data input and output functions  Formatted Data input and output functions
  • 23. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES DATA INPUT OUTPUT FUNCTIONS Unformatted Data input and output functions The unformatted functions are not capable of controlling the format that is involved in writing and reading the available data.  getchar() & putchar() functions  gets() & puts() functions
  • 24. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES DATA INPUT OUTPUT FUNCTIONS Formatted Data input and output functions  printf( )  scnanf( ) The formatted functions basically present or accept the available data (input) in a specific format.
  • 25. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES DATA INPUT OUTPUT FUNCTIONS printf( ) function printf() is formatted output function which is used to display some information on standard output unit. Syntax printf(“format_specifies”, var1, var2, var3, …, varN);
  • 26. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES DATA INPUT OUTPUT FUNCTIONS scanf( ) function scanf() is formatted input function which is used to read formatted data from standard input device and automatically converts numeric information to integers and floats. It is defined in stdio.h. Syntax scanf(“format_string”, &var1, &var2, &var3, …, &varN);
  • 27. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES SIMPLE C PROGRAMS #include <stdio.h> void main() { int number; printf("Enter an integer: "); scanf("%d", &number); printf("You entered: %d", number); }
  • 28. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES FLOW OF CONTROL A special statement to control the execution of one or more statements depending on a condition. Such statements are called control statements or control-flow statements. Types of control-flow statements  Selection Statement  Iterative Statement  Unconditional Control Statement
  • 29. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES Selection Statement It is a statement whose execution results in a choice being made as to which of two or more paths should be followed.  if construct  if-else construct  if-else-if construct  Nested if-else-if construct  switch-case construct
  • 30. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES IF STATEMENT The if construct is a selective statement, the statements within the block are executed only once when the condition evaluates to true, otherwise the control goes to the first statement after the if construct.
  • 31. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES IF STATEMENT The general form if (condition) { statement-1; statement-2; .... statement-n; }
  • 32. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES IF STATEMENT
  • 33. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES IF-ELSE STATEMENT An if statement will execute its block only when the condition evaluates to 1 (true). We can also conditionally execute another block when the condition evaluates to 0 (false) using the else construct.
  • 34. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES IF-ELSE STATEMENT The general syntax if (expression) { statement-1; } else { statement-2; }
  • 35. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES IF-ELSE STATEMENT
  • 36. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES IF-ELSE-IF STATEMENT Multiple if constructs can be chained to any length. The else construct which appears at the end is optional, and if it is to be included it has to be only at the end. The if-else-if construct is used whenever we have multiple mutually exclusive if conditions that work on the same input.
  • 37. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES IF-ELSE-IF STATEMENT General form if (expression_1) { statement_1; } else if (expression_2) { statement_2; } else if (expression_3) { statement_3; } else if (expression_4) { statement_4; } else { statement_5; }
  • 38. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT The process of repeatedly executing a statement or group of statements until the condition is satisfied is called looping.  While loop  Do..while loop  for loop
  • 39. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT WHILE LOOP To evaluate a test condition and iterate over the loop body until the condition returns True. The loop ends when the condition returns False.
  • 40. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT while (condition) { body of while loop }
  • 41. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT
  • 42. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT DO….WHILE LOOP The body is executed if and only if the condition is true. In some cases, we have to execute a body of the loop at least once even if the condition is false. This type of operation can be achieved by using a do-while loop.
  • 43. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT DO….WHILE LOOP do { statements } while (expression);
  • 44. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT
  • 45. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT FOR LOOP The initial value of the for loop is performed only once. The condition is a Boolean expression that tests and compares the counter to a fixed value after each iteration, stopping the for loop when false is returned. The incrementation/decrementation increases (or decreases) the counter by a set value.
  • 46. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT FOR LOOP Syntax for (initial value; condition; incrementation or decrementation ) { statements; }
  • 47. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES LOOP STATEMENT
  • 48. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES SWITCH The switch statement allows us to execute one code block among many alternatives.
  • 49. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES switch (expression) { case constant1: // statements break; case constant2: // statements break; . . . default: // default statements }
  • 50. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES
  • 51. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES BREAK AND CONTINUE Break The break statement ends the loop immediately when it is encountered. syntax break;
  • 52. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES BREAK AND CONTINUE Continue The continue statement skips the current iteration of the loop and continues with the next iteration. Syntax continue;
  • 53. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES GO - TO STATEMENTS The goto statement allows us to transfer control of the program to the specified label. Syntax goto label; ... .. ... ... .. ... label: statement;
  • 54. INPUT, OUTPUT FUNCTIONS AND CONTROL STRUCTURES COMMA OPERATOR The comma operator in C is denoted by ,. The comma operator in C has the least precedence. The comma operator in C ensures that two or more expressions separated by commas are evaluated one by one from left to right, and the result of the entire expression is the value of the rightmost expression.
  • 55. FUNCTIONS Definition A function is a block of code that performs a specific task. Benefits of functions Enables reusability and reduces redundancy Makes a code modular Provides abstraction functionality The program becomes easy to understand and manage Breaks an extensive program into smaller and simpler pieces
  • 56. FUNCTIONS Basic Syntax of Functions return_type function_name(arg1, arg2, … argn) { Body of the function //Statements to be processed }
  • 57. FUNCTIONS FUNCTION PROTO-TYPES A function prototype is a declaration in the code that instructs the compiler about the data type of the function, arguments and parameter list. As we all know that a block of code which performs a specific task is called as a function.
  • 58. FUNCTIONS Syntax returntypefunctionname(datatype paramter1 , datatype paramter2 , datatype paramter3..);
  • 59. FUNCTIONS PASSING ARGUMENTS C programming function arguments also known as parameters are the variables that will receive the data sent by the calling program. These arguments serve as input data to the function to carry out the specified task.
  • 61. FUNCTIONS Function arguments in c programming Basically, there are two types of arguments: Actual arguments Formal arguments
  • 62. FUNCTIONS Function arguments in c programming Two ways to pass arguments to the function Pass by Value Pass by value is a method in which a copy of the value of the variables is passed to the function for the specific operation. Pass by reference Pass by reference is a method in which rather than passing direct value the address of the variable is passed as an argument to the called function.
  • 63. FUNCTIONS RECURSIONS A function that calls itself is known as a recursive function. And, this technique is known as recursion. void recurse() { ... .. ... recurse(); ... .. ... } int main() { ... .. ... recurse(); ... .. ... }
  • 64. FUNCTIONS STORAGE CLASSES The variable scope. The location where the variable will be stored. The initialized value of a variable. A lifetime of a variable.
  • 65. FUNCTIONS There are 4 types of storage class  automatic  external  static  register
  • 66. FUNCTIONS MULTIFILE PROGRAMS If a program contains many functions then it is difficult to read and maintain because when the number of functions increases the size of the program/file will also increase. To avoid this some functions can be written in separate file The individual files will be compiled separately and then linked together to form one executable object program.
  • 67. FUNCTIONS MULTIFILE PROGRAMS If a program contains many functions then it is difficult to read and maintain because when the number of functions increases the size of the program/file will also increase. To avoid this some functions can be written in separate file The individual files will be compiled separately and then linked together to form one executable object program.
  • 68. ARRAYS An array is a collection of variables of same data types. Advantage of Arrays Less amount of code : Easy access of elements : Easy to implement algorithms : Random Access :
  • 69. ARRAYS Declare an array dataType arrayName[arraySize]; Example float mark[5];
  • 70. ARRAYS Types of Array 1. Single dimensional arrays 2. Multidimensional arrays
  • 71. ARRAYS Single dimensional arrays Single dimensional array or 1-D array is the simplest form of arrays that can be found in C. This type of array consists of elements of similar types and these elements can be accessed through their indices.
  • 72. ARRAYS Multi-dimensional Arrays The most common type of multi-dimensional array that is used in the C language is a 2-D array. However, the number of dimensions can be more than 2 depending upon the compiler of the user’s system. These arrays consist of elements that are array themselves.
  • 74. PASSING ARRAYS TO FUNCTIONS An array is a collection of similar data types which are stored in memory as a contiguous memory block. This means multi-dimensional arrays are also a continuous block of data in our memory. In C, there are several times when we are required to pass an array to a function argument.
  • 75. ARRAYS AND STRING A string is a sequence of characters terminated with a null character. Example char c[] = "c string";
  • 76. STRUCTURES A struct (or structure) is a collection of variables (can be of different types) under a single name. To define a struct, the struct keyword is used.
  • 77. STRUCTURES Syntax of struct struct structureName { dataType member1; dataType member2; ... };
  • 78. USER DEFINED DATA TYPES  Structure  Union  Enumeration
  • 79. USER DEFINED DATA TYPES Union A union is also a user-defined data type. It also holds members of different data types under a single name. A union sounds similar to a structure and they are similar in conceptual terms. But there are some major differences between the two. While a structure allocates sufficient memory for all its members, a union only allocates memory equal to its largest member.
  • 80. USER DEFINED DATA TYPES Union Syntax union union_name { data_type var1; data_type var2; };
  • 81. USER DEFINED DATA TYPES Enumeration Enumeration or simply enum is one of the user-defined data types in C which provides a special type of flexibility of defining variables. An enum consists of a set of integer constants that can be replaced by user-defined names. Syntax enum flag {const_name1, const_name2, ..., const_nameN};
  • 82. PASSING STRUCTURES TO FUNCTIONS A structure can be passed to any function from main function or from any sub function. Structure definition will be available within the function only. It won’t be available to other functions unless it is passed to those functions by value or by address(reference).
  • 83. PASSING STRUCTURES TO FUNCTIONS Passing structure to function It can be done in below 3 ways. 1. Passing structure to a function by value 2. Passing structure to a function by address(reference) 3. No need to pass a structure – Declare structure variable as global
  • 84. SELF-REFERENTIAL STRUCTURES A self-referential structure is a structure that contains a pointer to a variable of the same type. This allows the structure to refer to itself, creating a linked data structure. The concept of a self-referential structure is based on the idea of a linked list, which is a collection of data elements that are connected to each other through a series of pointers.
  • 85. BITWISE OPERATIONS In the arithmetic-logic unit (which is within the CPU), mathematical operations like: addition, subtraction, multiplication and division are done in bit-level. To perform bit- level operations in C programming, bitwise operators are used.
  • 86. POINTERS A Pointer is a variable that holds the memory address of another variable. POINTER DECLARATION datatype *pointer_variableName; Example int *ptr;
  • 87. POINTERS A Pointer is a variable that holds the memory address of another variable. POINTER DECLARATION datatype *pointer_variableName; Example int *ptr;
  • 88. PASSING POINTERS TO FUNCTIONS Pointers can also be passed as an argument to a function like any other argument. Instead of a variable. Declare a function which accepts a pointer as an argument return_type function_name(int*);
  • 89. OPERATION IN POINTERS An address in a memory is a numeric value we can perform arithmetic operations on the pointer values. Different operations Assignment Value finding Taking a pointer address Incrementing and Decrement a pointer
  • 90. POINTER AND ARRAYS Pointers and Array representations are very much related to each other and can be interchangeably used in the right context. Arrays can be single or multidimensional and are stored in contiguous memory blocks in our system.
  • 91. ARRAYS AND POINTERS Pointer Address of a variable in memory. Allows us to indirectly access variables. Arrays Array is a group of elements that share a common name, and that are different from one another by their positions within the array.
  • 93. STRUCTURES AND POINTERS Structure pointer points to the address of the structure variable in the memory block to which it points. This pointer can be used to access and change the value of structure members.
  • 94. STRUCTURES AND POINTERS struct name { member1; member2; . . }; int main() { struct name *ptr, Harry; }
  • 95. FILES A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage of data. It is a ready made structure. A file is a container in computer storage devices used for storing data.
  • 96. FILES Basic file operations Function Description fopen() create a new file or open a existing file fclose() closes a file getc() reads a character from a file putc() writes a character to a file fscanf() reads a set of data from a file fprintf() writes a set of data to a file getw() reads a integer from a file putw() writes a integer to a file fseek() set the position to desire point ftell() gives current position in the file rewind() set the position to the begining point