SlideShare a Scribd company logo
1 of 19
GROUP # 04
GROUP MEMBERS;
HAFIZ AHMAD ALI EN-15024
SAQIB KHOKHAR EN-15017
HASNAIN BILAL EN-15025
GLOBAL VARIABLE
• GLOBAL VARIABLES HOLD THEIR VALUES THROUGHOUT THE LIFETIME OF YOUR PROGRAM AND
THEY CAN BE ACCESSED INSIDE ANY OF THE FUNCTIONS DEFINED FOR THE PROGRAM.
• GLOBAL AND LOCAL VARIABLES
• A LOCAL VARIABLE IS A VARIABLE THAT IS DECLARED INSIDE A FUNCTION.
• A GLOBAL VARIABLE IS A VARIABLE THAT IS DECLARED OUTSIDE ALL FUNCTIONS.
• A LOCAL VARIABLE CAN ONLY BE USED IN THE FUNCTION WHERE IT IS DECLARED.
• A GLOBAL VARIABLE CAN BE USED IN ALL FUNCTIONS.
#include<stdio.h> // Global variables int A; int B; int Add() { return A + B; } int main() { int answer; // Local variable A = 5; B = 7; answer = Add(); printf("%dn",answer); return 0; }
Sorting
 To arrange a set of items in sequence.
 Many applications require sorting;
 Many applications perform sorting when
they don't have to;
 Many applications use inefficient sorting
algorithms.
Sorting Applications
 To prepare a list of student ID, names, and
scores in a table (sorted by ID or name) for
easy checking.
 To prepare a list of scores before letter
grade assignment.
 To produce a list of horses after a race
(sorted by the finishing times) for payoff
calculation.
 To prepare an originally unsorted array for
ordered binary searching.
Static and Automatic
Variables
• Automatic variable - memory is allocated
at block entry and deallocated at block
exit
• Static variable - memory remains
allocated as long as the program
executes
• Variables declared outside of any block
are static variables
• By default, variables declared within a
block are automatic variables
• Declare a static variable within a block by
using the reserved word static
Static and Automatic
Variables (continued)
• The syntax for declaring a static variable
is:
static dataType identifier;
• The statement
static int x;
declares x to be a static variable of the type
int
• Static variables declared within a block
are local to the block
• Their scope is the same as any other
Summary (continued)
• An automatic variable is a variable for
which memory is allocated on function
(or block) entry and deallocated on
function (or block) exit
• A static variable is a variable for which
memory remains allocated throughout
the execution of the program
• C allows functions to have default
parameters
FUNCTIONS
Basically there are two categories of function:
1. Predefined functions: available in C / C++
standard library such as stdio.h, math.h,
string.h etc.
2. User-defined functions: functions that
programmers create for specialized tasks such
as graphic and multimedia libraries,
implementation extensions or dependent etc.
FUNCTION & ARRAY:
FOR A FUNCTION TO RECEIVE AN ARRAY THROUGH A FUNCTION CALL, THE
FUNCTION’S PARAMETER LIST MUST SPECIFY THAT AN ARRAY WILL BE RECEIVED.
SYNTAX
INDICATING THAT MODIFY ARRAY EXPECTS TO RECEIVE AN ARRAY OF INTEGERS
IN PARAMETER B AND THE NUMBER OF ARRAY ELEMENTS IN PARAMETER SIZE.
THE SIZE OF THE ARRAY IS NOT REQUIRED BETWEEN
THE ARRAY BRACKETS.
#include <stdio.h>
float average(float a[]);
int main(){
float avg, c[]={23.4, 55, 22.6, 3, 40.5, 18};
avg=average(c); /* Only name of array is passed as argument. */
printf("Average age=%.2f",avg);
return 0;
}
float average(float a[ ])
{
int i;
float avg, sum=0.0;
for(i=0;i<6;++i){
sum+=a[i];
}
avg =(sum/6);
return avg;
}
Output Average age=27.08
C program to pass an array containing age of person to a function. This function should find average
age and display the average age in main function.
#include
void Function(int c[2][2]);
int main(){
int c[2][2],i,j;
printf("Enter 4 numbers:n");
for(i=0;i<2;++i)
for(j=0;j<2;++j){
scanf("%d",&c[i][j]);
}
Function(c); /* passing multi-dimensional array to function */
return 0;
}
void Function(int c[2][2]){
/* Instead to above line, void Function(int c[][2]){ is also valid */
int i,j;
printf("Displaying:n");
for(i=0;i<2;++i)
for(j=0;j<2;++j)
printf("%dn",c[i][j]);
} Output
Enter 4 numbers:
2
3
4
5
Displaying:
2
3
4
5
Global variables, sorting static variables,function and arrays,

More Related Content

What's hot

What's hot (20)

Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
Method parameters in c#
Method parameters in c#Method parameters in c#
Method parameters in c#
 
Fda unit 1 lec 1
Fda unit 1 lec  1Fda unit 1 lec  1
Fda unit 1 lec 1
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
201801 CSE240 Lecture 06
201801 CSE240 Lecture 06201801 CSE240 Lecture 06
201801 CSE240 Lecture 06
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
 
Storage classes in C
Storage classes in CStorage classes in C
Storage classes in C
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Cinfo
CinfoCinfo
Cinfo
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
Storage class in c
Storage class in cStorage class in c
Storage class in c
 
Functions
FunctionsFunctions
Functions
 
Storage class
Storage classStorage class
Storage class
 
Function in c
Function in cFunction in c
Function in c
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 

Viewers also liked

CS Unitec Nut Runners
CS Unitec Nut RunnersCS Unitec Nut Runners
CS Unitec Nut RunnersCS Unitec
 
Stat family :Role of Stat 3 in skin disorders by yousry
Stat family :Role of Stat 3 in skin disorders  by yousryStat family :Role of Stat 3 in skin disorders  by yousry
Stat family :Role of Stat 3 in skin disorders by yousryM.YOUSRY Abdel-Mawla
 
Transients characteristics
Transients characteristicsTransients characteristics
Transients characteristicsAldo Uribe
 
The osterberg cell static loading test
The osterberg cell static loading testThe osterberg cell static loading test
The osterberg cell static loading testAlaa Metwally
 
Pecha - Kucha
Pecha - KuchaPecha - Kucha
Pecha - KuchaLookgade
 
Managerial Accounting
Managerial AccountingManagerial Accounting
Managerial AccountingMelody Chen
 
Management reporting
Management reportingManagement reporting
Management reportingPw Botha
 
Requirements - Part 1
Requirements - Part 1Requirements - Part 1
Requirements - Part 1stat
 
Measurement of hydraulic pipe and hose dynamic
Measurement of hydraulic pipe and hose dynamicMeasurement of hydraulic pipe and hose dynamic
Measurement of hydraulic pipe and hose dynamicFLUIDON GmbH
 
Stat3 protein in psoriasis by yousry
Stat3 protein in psoriasis  by yousryStat3 protein in psoriasis  by yousry
Stat3 protein in psoriasis by yousryM.YOUSRY Abdel-Mawla
 
Hydraulic Ram; by Allen Inversin, VITA
Hydraulic Ram; by Allen Inversin, VITAHydraulic Ram; by Allen Inversin, VITA
Hydraulic Ram; by Allen Inversin, VITAFatin62c
 
Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016Viet-Dung TRINH
 
CS Unitec Pneumatic & Hydraulic Nut Runners
CS Unitec Pneumatic & Hydraulic Nut RunnersCS Unitec Pneumatic & Hydraulic Nut Runners
CS Unitec Pneumatic & Hydraulic Nut RunnersCS Unitec
 
Hidraulika
HidraulikaHidraulika
HidraulikaNanang s
 
Inference of the JAK-STAT Gene Network via Graphical Models
Inference of the JAK-STAT Gene Network via Graphical ModelsInference of the JAK-STAT Gene Network via Graphical Models
Inference of the JAK-STAT Gene Network via Graphical ModelsSSA KPI
 
Lesson 5: Thesis Statements
Lesson 5: Thesis StatementsLesson 5: Thesis Statements
Lesson 5: Thesis Statementsbsimoneaux
 

Viewers also liked (20)

CS Unitec Nut Runners
CS Unitec Nut RunnersCS Unitec Nut Runners
CS Unitec Nut Runners
 
Stat family :Role of Stat 3 in skin disorders by yousry
Stat family :Role of Stat 3 in skin disorders  by yousryStat family :Role of Stat 3 in skin disorders  by yousry
Stat family :Role of Stat 3 in skin disorders by yousry
 
JACK-IT® Line Card
JACK-IT® Line CardJACK-IT® Line Card
JACK-IT® Line Card
 
Transients characteristics
Transients characteristicsTransients characteristics
Transients characteristics
 
The osterberg cell static loading test
The osterberg cell static loading testThe osterberg cell static loading test
The osterberg cell static loading test
 
Grammarware Memes
Grammarware MemesGrammarware Memes
Grammarware Memes
 
Pecha - Kucha
Pecha - KuchaPecha - Kucha
Pecha - Kucha
 
Managerial Accounting
Managerial AccountingManagerial Accounting
Managerial Accounting
 
E470 20MnV6 Steel Pipe for Hydraulic Cylinders
E470 20MnV6 Steel Pipe for Hydraulic CylindersE470 20MnV6 Steel Pipe for Hydraulic Cylinders
E470 20MnV6 Steel Pipe for Hydraulic Cylinders
 
Management reporting
Management reportingManagement reporting
Management reporting
 
Requirements - Part 1
Requirements - Part 1Requirements - Part 1
Requirements - Part 1
 
Measurement of hydraulic pipe and hose dynamic
Measurement of hydraulic pipe and hose dynamicMeasurement of hydraulic pipe and hose dynamic
Measurement of hydraulic pipe and hose dynamic
 
Stat3 protein in psoriasis by yousry
Stat3 protein in psoriasis  by yousryStat3 protein in psoriasis  by yousry
Stat3 protein in psoriasis by yousry
 
Hydraulic Ram; by Allen Inversin, VITA
Hydraulic Ram; by Allen Inversin, VITAHydraulic Ram; by Allen Inversin, VITA
Hydraulic Ram; by Allen Inversin, VITA
 
Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016Apache zookeeper seminar_trinh_viet_dung_03_2016
Apache zookeeper seminar_trinh_viet_dung_03_2016
 
CS Unitec Pneumatic & Hydraulic Nut Runners
CS Unitec Pneumatic & Hydraulic Nut RunnersCS Unitec Pneumatic & Hydraulic Nut Runners
CS Unitec Pneumatic & Hydraulic Nut Runners
 
Hidraulika
HidraulikaHidraulika
Hidraulika
 
Inference of the JAK-STAT Gene Network via Graphical Models
Inference of the JAK-STAT Gene Network via Graphical ModelsInference of the JAK-STAT Gene Network via Graphical Models
Inference of the JAK-STAT Gene Network via Graphical Models
 
Hydraulic losses in pipe
Hydraulic losses in pipeHydraulic losses in pipe
Hydraulic losses in pipe
 
Lesson 5: Thesis Statements
Lesson 5: Thesis StatementsLesson 5: Thesis Statements
Lesson 5: Thesis Statements
 

Similar to Global variables, sorting static variables,function and arrays,

Similar to Global variables, sorting static variables,function and arrays, (20)

C language
C languageC language
C language
 
STORAGE CLASS.pptx
STORAGE CLASS.pptxSTORAGE CLASS.pptx
STORAGE CLASS.pptx
 
C language updated
C language updatedC language updated
C language updated
 
visiblity and scope.pptx
visiblity and scope.pptxvisiblity and scope.pptx
visiblity and scope.pptx
 
Unit iii
Unit iiiUnit iii
Unit iii
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Storage classes
Storage classesStorage classes
Storage classes
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Terms and Definitions.pdf
Terms and Definitions.pdfTerms and Definitions.pdf
Terms and Definitions.pdf
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Storage class
Storage classStorage class
Storage class
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
 
C language
C languageC language
C language
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
C
CC
C
 

Recently uploaded

Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 

Recently uploaded (20)

Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 

Global variables, sorting static variables,function and arrays,

  • 1.
  • 2. GROUP # 04 GROUP MEMBERS; HAFIZ AHMAD ALI EN-15024 SAQIB KHOKHAR EN-15017 HASNAIN BILAL EN-15025
  • 3. GLOBAL VARIABLE • GLOBAL VARIABLES HOLD THEIR VALUES THROUGHOUT THE LIFETIME OF YOUR PROGRAM AND THEY CAN BE ACCESSED INSIDE ANY OF THE FUNCTIONS DEFINED FOR THE PROGRAM. • GLOBAL AND LOCAL VARIABLES • A LOCAL VARIABLE IS A VARIABLE THAT IS DECLARED INSIDE A FUNCTION. • A GLOBAL VARIABLE IS A VARIABLE THAT IS DECLARED OUTSIDE ALL FUNCTIONS. • A LOCAL VARIABLE CAN ONLY BE USED IN THE FUNCTION WHERE IT IS DECLARED. • A GLOBAL VARIABLE CAN BE USED IN ALL FUNCTIONS.
  • 4. #include<stdio.h> // Global variables int A; int B; int Add() { return A + B; } int main() { int answer; // Local variable A = 5; B = 7; answer = Add(); printf("%dn",answer); return 0; }
  • 5. Sorting  To arrange a set of items in sequence.  Many applications require sorting;  Many applications perform sorting when they don't have to;  Many applications use inefficient sorting algorithms.
  • 6. Sorting Applications  To prepare a list of student ID, names, and scores in a table (sorted by ID or name) for easy checking.  To prepare a list of scores before letter grade assignment.  To produce a list of horses after a race (sorted by the finishing times) for payoff calculation.  To prepare an originally unsorted array for ordered binary searching.
  • 7.
  • 8.
  • 9. Static and Automatic Variables • Automatic variable - memory is allocated at block entry and deallocated at block exit • Static variable - memory remains allocated as long as the program executes • Variables declared outside of any block are static variables • By default, variables declared within a block are automatic variables • Declare a static variable within a block by using the reserved word static
  • 10. Static and Automatic Variables (continued) • The syntax for declaring a static variable is: static dataType identifier; • The statement static int x; declares x to be a static variable of the type int • Static variables declared within a block are local to the block • Their scope is the same as any other
  • 11. Summary (continued) • An automatic variable is a variable for which memory is allocated on function (or block) entry and deallocated on function (or block) exit • A static variable is a variable for which memory remains allocated throughout the execution of the program • C allows functions to have default parameters
  • 12. FUNCTIONS Basically there are two categories of function: 1. Predefined functions: available in C / C++ standard library such as stdio.h, math.h, string.h etc. 2. User-defined functions: functions that programmers create for specialized tasks such as graphic and multimedia libraries, implementation extensions or dependent etc.
  • 13. FUNCTION & ARRAY: FOR A FUNCTION TO RECEIVE AN ARRAY THROUGH A FUNCTION CALL, THE FUNCTION’S PARAMETER LIST MUST SPECIFY THAT AN ARRAY WILL BE RECEIVED. SYNTAX INDICATING THAT MODIFY ARRAY EXPECTS TO RECEIVE AN ARRAY OF INTEGERS IN PARAMETER B AND THE NUMBER OF ARRAY ELEMENTS IN PARAMETER SIZE. THE SIZE OF THE ARRAY IS NOT REQUIRED BETWEEN THE ARRAY BRACKETS.
  • 14.
  • 15. #include <stdio.h> float average(float a[]); int main(){ float avg, c[]={23.4, 55, 22.6, 3, 40.5, 18}; avg=average(c); /* Only name of array is passed as argument. */ printf("Average age=%.2f",avg); return 0; } float average(float a[ ]) { int i; float avg, sum=0.0; for(i=0;i<6;++i){ sum+=a[i]; } avg =(sum/6); return avg; } Output Average age=27.08 C program to pass an array containing age of person to a function. This function should find average age and display the average age in main function.
  • 16.
  • 17. #include void Function(int c[2][2]); int main(){ int c[2][2],i,j; printf("Enter 4 numbers:n"); for(i=0;i<2;++i) for(j=0;j<2;++j){ scanf("%d",&c[i][j]); } Function(c); /* passing multi-dimensional array to function */ return 0; }
  • 18. void Function(int c[2][2]){ /* Instead to above line, void Function(int c[][2]){ is also valid */ int i,j; printf("Displaying:n"); for(i=0;i<2;++i) for(j=0;j<2;++j) printf("%dn",c[i][j]); } Output Enter 4 numbers: 2 3 4 5 Displaying: 2 3 4 5