SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
Embedded C – Part II
Arrays & Functions
Team Emertxe
Functions
Why Functions?
● Reusability
● Functions can be stored in library & re-used
● When some specific code is to be used more than once, at different places, functions
avoids repeatition of the code.
● Divide & Conquer
● A big & difficult problem can be divided into smaller sub-problems and solved using
divide & conquer technique
● Modularity can be achieved.
● Code can be easily understandable & modifiable.
● Functions are easy to debug & test.
● One can suppress, how the task is done inside the function, which is called
Abstraction.
Parameters, Arguments and Return
Values
Parameters, Arguments
and Return Values
● Parameters are also commonly referred to as arguments, though arguments
are more properly thought of as the actual values or references assigned to
the parameter variables when the subroutine is called at runtime.
● When discussing code that is calling into a subroutine,any values or references
passed into the subroutine are the arguments, and the place in the code
where these values or references are given is the parameter list.
● When discussing the code inside the subroutine definition, the variables in the
subroutine’s parameter list are the parameters, while the values of the
parameters at runtime are the arguments.
Parameters, Arguments
and Return Values
Actual Arguments
Formal ArgumentsReturn
type
Example
Function and the Stack
P1
P2
P3
P4
:
:
:
Pn-1
Pn
RAM
Command line
Arguments
Stack
HOLE
Heap
.BSS(Uninitialized
Data segment)
Initialized data
Segment
Code Segment
Data
Segment
Parameter List
Return Address
Local Variables
StackMemory Layout
Various Passing Mechanisms
Various Passing
Mechanisms
Pass by Value Pass by reference
● This method copies the actual value of an
argument into the formal parameter of the
function.
● In this case, changes made to the
parameter inside the function have no
effect on the actual argument.
● This method copies the address of an
argument into the formal parameter.
●
Inside the function, the address is used to
access the actual argument used in the
call. This means that changes made to the
parameter affect the argument.
Pass by value
ExampleExample
O / P ???
Pass by reference
Example
O / P ???
Pass by value &
Pass by reference
DIY
Problem 1:
Write a function to swap two integers passed from main function.
Problem 2:
Write a function to perform both sum & product of two different integers
passed from main function.
Ignoring Function’s Return
Value
Ingnoring the function's
return value

In C tradition, you can choose to ignore to capture the

return value from a method:
● Function read_int returning an int
And collecting in variable i in the
main function.
● Main function ignoring the return
value.
Introduction : Arrays
Introduction
● An array is a collection of data of similar data type.
● Example:
If we want to store the ages of 5 different people, then we can use array instead
of using 5 different variables.
● The mory alloaction will be contiguos.
● A specific element in an array is accessed by an index.
Array: Declaration
Syntax
type arrayName [ SIZE ];
Example
To declare an array to store ages of 5 people
int age[ 5 ];
Total Memory
Total Memory = SIZE * sizeof(dataType)
= 5 * sizeof( int ) // Assuming sizeof(int) = 4
= 5 * 4
= 20 bytes
Array: Definition
Example
To declare an array to store ages of 5 people
int age[ 5 ] = {10, 20, 30, 40, 50};
Memory Allocation
10 20 30 40 50
age[0]
age[4]
age[3]
age[2]
age[1]
100 104 108 112 116

DIY : Write a program to add all the elements of the array.
Array: Passing to function
DIY: WAF to sort the elements of the array in asc / des order.
Returning the array from the
function
Array: Passing to function
Static keyword is used to retain the values between the function

calls
Variadic functions
Variadic Functions:
Introduction
● Variadic functions can be called with any number of trailing arguments.
For example,
printf(), scanf() are common variadic funtions
● Variadic functions can be called in the usual way with individual arguments.
syntax
return_type function_name(parameter list, ...);
Variadic Functions:
How are defined & used
Defining and using a variadic function involves three steps:
step 1: Variadic functions are defined using an ellipsis (‘
’) in the argument list,
and using special macros to access the variable arguments.
For example,
step 2: Declare the function as variadic, using a prototype with an ellipsis (‘
’),
in all the files which call it.
Step 3: Call the function by writing the fixed arguments followed by the
additional variable arguments.
Variadic Functions:
Arguments access macros
● Descriptions of the macros used to retrieve variable arguments.
● These macros are defined in the header file stdarg.h
Type/
Macros
Description
va_list The type va_list is used for argument pointer variables
va_start This macro initializes the argument pointer variable ap to point to the first
of the optional arguments of the current function; last-required must be
the last required argument to the function
va_arg The va_arg macro returns the value of the next optional argument, and
modifies the value of ap to point to the subsequent argument. Thus,
successive uses of va_arg return successive optional arguments
va_end This ends the use of ap
Variadic Functions:
Example
Recursive functions
Recursive Function
● Function calling itself
Steps:
1. Identification of the base case.
2. Writing the recursive case.
Example Factorial of a number
n !
1 n = 0 (Base case)
n * (n – 1) ! n > 0 (Recursive case)
Recursive Functions:
Example
Recursive Functions:
Example
Stay connected
About us: Emertxe is India’s one of the top IT finishing schools & self learning
kits provider. Our primary focus is on Embedded with diversification focus on
Java, Oracle and Android areas
Branch Office: Corporate Headquarters:
Emertxe Information Technologies, Emertxe Information Technologies,
No-1, 9th Cross, 5th Main, 83, Farah Towers, 1st
Floor,
Jayamahal Extension, MG Road,
Bangalore, Karnataka 560046 Bangalore, Karnataka - 560001
T: +91 809 555 7333 (M), +91 80 41289576 (L)
E: training@emertxe.com
https://www.facebook.com/Emertxe https://twitter.com/EmertxeTweet https://www.slideshare.net/EmertxeSlides
THANK YOU

Weitere Àhnliche Inhalte

Was ist angesagt?

detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c languagegourav kottawar
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1Mohamed Abdallah
 

Was ist angesagt? (20)

Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
 
Micro-controllers (PIC) based Application Development
Micro-controllers (PIC) based Application DevelopmentMicro-controllers (PIC) based Application Development
Micro-controllers (PIC) based Application Development
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Advanced C - Part 3
Advanced C - Part 3Advanced C - Part 3
Advanced C - Part 3
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
Intro to Embedded OS, RTOS and Communication Protocols
Intro to Embedded OS, RTOS and Communication ProtocolsIntro to Embedded OS, RTOS and Communication Protocols
Intro to Embedded OS, RTOS and Communication Protocols
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
 
EMBEDDED C
EMBEDDED CEMBEDDED C
EMBEDDED C
 
Linux Internals - Part III
Linux Internals - Part IIILinux Internals - Part III
Linux Internals - Part III
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
CS3251-_PIC
CS3251-_PICCS3251-_PIC
CS3251-_PIC
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
C programming session6
C programming  session6C programming  session6
C programming session6
 

Andere mochten auch

Standard embedded c
Standard embedded cStandard embedded c
Standard embedded cTam Thanh
 
13986149 c-pgming-for-embedded-systems
13986149 c-pgming-for-embedded-systems13986149 c-pgming-for-embedded-systems
13986149 c-pgming-for-embedded-systemsPRADEEP
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c languageIndia
 
Microcontroladores pic basic carlos a reyes
Microcontroladores pic basic   carlos a reyesMicrocontroladores pic basic   carlos a reyes
Microcontroladores pic basic carlos a reyesJunior Kevin Aviles Torres
 
Microcontroladores pic basic_-
Microcontroladores pic basic_-Microcontroladores pic basic_-
Microcontroladores pic basic_-Nando Sata
 
Microcontrollers(8051) Notes written by Arun Kumar G, Associate Professor, De...
Microcontrollers(8051) Notes written by Arun Kumar G, Associate Professor, De...Microcontrollers(8051) Notes written by Arun Kumar G, Associate Professor, De...
Microcontrollers(8051) Notes written by Arun Kumar G, Associate Professor, De...Arunkumar Gowdru
 
Cmp104 lec 7 algorithm and flowcharts
Cmp104 lec 7 algorithm and flowchartsCmp104 lec 7 algorithm and flowcharts
Cmp104 lec 7 algorithm and flowchartskapil078
 
Discrete cosine transform
Discrete cosine transformDiscrete cosine transform
Discrete cosine transformaniruddh Tyagi
 
A project on advanced C language
A project on advanced C languageA project on advanced C language
A project on advanced C languagesvrohith 9
 
whitepaper_mpeg-if_understanding_mpeg4
whitepaper_mpeg-if_understanding_mpeg4whitepaper_mpeg-if_understanding_mpeg4
whitepaper_mpeg-if_understanding_mpeg4aniruddh Tyagi
 

Andere mochten auch (17)

C Programming - Refresher - Part IV
C Programming - Refresher - Part IVC Programming - Refresher - Part IV
C Programming - Refresher - Part IV
 
Embedded C - Optimization techniques
Embedded C - Optimization techniquesEmbedded C - Optimization techniques
Embedded C - Optimization techniques
 
Standard embedded c
Standard embedded cStandard embedded c
Standard embedded c
 
13986149 c-pgming-for-embedded-systems
13986149 c-pgming-for-embedded-systems13986149 c-pgming-for-embedded-systems
13986149 c-pgming-for-embedded-systems
 
Data Structures & Algorithm design using C
Data Structures & Algorithm design using C Data Structures & Algorithm design using C
Data Structures & Algorithm design using C
 
Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
 
Microcontroladores pic basic carlos a reyes
Microcontroladores pic basic   carlos a reyesMicrocontroladores pic basic   carlos a reyes
Microcontroladores pic basic carlos a reyes
 
Microcontroladores pic basic_-
Microcontroladores pic basic_-Microcontroladores pic basic_-
Microcontroladores pic basic_-
 
Microcontrollers(8051) Notes written by Arun Kumar G, Associate Professor, De...
Microcontrollers(8051) Notes written by Arun Kumar G, Associate Professor, De...Microcontrollers(8051) Notes written by Arun Kumar G, Associate Professor, De...
Microcontrollers(8051) Notes written by Arun Kumar G, Associate Professor, De...
 
Cmp104 lec 7 algorithm and flowcharts
Cmp104 lec 7 algorithm and flowchartsCmp104 lec 7 algorithm and flowcharts
Cmp104 lec 7 algorithm and flowcharts
 
Discrete cosine transform
Discrete cosine transformDiscrete cosine transform
Discrete cosine transform
 
DVB_Arch
DVB_ArchDVB_Arch
DVB_Arch
 
Advformat_0609
Advformat_0609Advformat_0609
Advformat_0609
 
A project on advanced C language
A project on advanced C languageA project on advanced C language
A project on advanced C language
 
whitepaper_mpeg-if_understanding_mpeg4
whitepaper_mpeg-if_understanding_mpeg4whitepaper_mpeg-if_understanding_mpeg4
whitepaper_mpeg-if_understanding_mpeg4
 
rsa-1
rsa-1rsa-1
rsa-1
 

Ähnlich wie C Programming - Refresher - Part II

Function
FunctionFunction
FunctionSaniati
 
C language presentation
C language presentationC language presentation
C language presentationbainspreet
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c languageTanmay Modi
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
Dive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfDive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfSudhanshiBakre1
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptxzueZ3
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptxManas40552
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and commentMalligaarjunanN
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxvekariyakashyap
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
Section-6-User-Defined-Functions.pdf
Section-6-User-Defined-Functions.pdfSection-6-User-Defined-Functions.pdf
Section-6-User-Defined-Functions.pdfjohnkyllelumacang699
 
Python_Unit_2.pdf
Python_Unit_2.pdfPython_Unit_2.pdf
Python_Unit_2.pdfalaparthi
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 

Ähnlich wie C Programming - Refresher - Part II (20)

Function
FunctionFunction
Function
 
C language presentation
C language presentationC language presentation
C language presentation
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Functions-.pdf
Functions-.pdfFunctions-.pdf
Functions-.pdf
 
Dive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfDive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdf
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
Functions
FunctionsFunctions
Functions
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and comment
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Python-Functions.pptx
Python-Functions.pptxPython-Functions.pptx
Python-Functions.pptx
 
Section-6-User-Defined-Functions.pdf
Section-6-User-Defined-Functions.pdfSection-6-User-Defined-Functions.pdf
Section-6-User-Defined-Functions.pdf
 
Functions.pptx
Functions.pptxFunctions.pptx
Functions.pptx
 
Python_Unit_2.pdf
Python_Unit_2.pdfPython_Unit_2.pdf
Python_Unit_2.pdf
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 

Mehr von Emertxe Information Technologies Pvt Ltd

Mehr von Emertxe Information Technologies Pvt Ltd (20)

premium post (1).pdf
premium post (1).pdfpremium post (1).pdf
premium post (1).pdf
 
Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf
10_isxdigit.pdf
 
01_student_record.pdf
01_student_record.pdf01_student_record.pdf
01_student_record.pdf
 
02_swap.pdf
02_swap.pdf02_swap.pdf
02_swap.pdf
 
01_sizeof.pdf
01_sizeof.pdf01_sizeof.pdf
01_sizeof.pdf
 
07_product_matrix.pdf
07_product_matrix.pdf07_product_matrix.pdf
07_product_matrix.pdf
 
06_sort_names.pdf
06_sort_names.pdf06_sort_names.pdf
06_sort_names.pdf
 
05_fragments.pdf
05_fragments.pdf05_fragments.pdf
05_fragments.pdf
 
04_magic_square.pdf
04_magic_square.pdf04_magic_square.pdf
04_magic_square.pdf
 
03_endianess.pdf
03_endianess.pdf03_endianess.pdf
03_endianess.pdf
 
02_variance.pdf
02_variance.pdf02_variance.pdf
02_variance.pdf
 
01_memory_manager.pdf
01_memory_manager.pdf01_memory_manager.pdf
01_memory_manager.pdf
 
09_nrps.pdf
09_nrps.pdf09_nrps.pdf
09_nrps.pdf
 
11_pangram.pdf
11_pangram.pdf11_pangram.pdf
11_pangram.pdf
 
10_combinations.pdf
10_combinations.pdf10_combinations.pdf
10_combinations.pdf
 
08_squeeze.pdf
08_squeeze.pdf08_squeeze.pdf
08_squeeze.pdf
 
07_strtok.pdf
07_strtok.pdf07_strtok.pdf
07_strtok.pdf
 
06_reverserec.pdf
06_reverserec.pdf06_reverserec.pdf
06_reverserec.pdf
 
05_reverseiter.pdf
05_reverseiter.pdf05_reverseiter.pdf
05_reverseiter.pdf
 

KĂŒrzlich hochgeladen

Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂșjo
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

KĂŒrzlich hochgeladen (20)

Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

C Programming - Refresher - Part II

  • 1. Embedded C – Part II Arrays & Functions Team Emertxe
  • 3. Why Functions? ● Reusability ● Functions can be stored in library & re-used ● When some specific code is to be used more than once, at different places, functions avoids repeatition of the code. ● Divide & Conquer ● A big & difficult problem can be divided into smaller sub-problems and solved using divide & conquer technique ● Modularity can be achieved. ● Code can be easily understandable & modifiable. ● Functions are easy to debug & test. ● One can suppress, how the task is done inside the function, which is called Abstraction.
  • 5. Parameters, Arguments and Return Values ● Parameters are also commonly referred to as arguments, though arguments are more properly thought of as the actual values or references assigned to the parameter variables when the subroutine is called at runtime. ● When discussing code that is calling into a subroutine,any values or references passed into the subroutine are the arguments, and the place in the code where these values or references are given is the parameter list. ● When discussing the code inside the subroutine definition, the variables in the subroutine’s parameter list are the parameters, while the values of the parameters at runtime are the arguments.
  • 6. Parameters, Arguments and Return Values Actual Arguments Formal ArgumentsReturn type Example
  • 7. Function and the Stack P1 P2 P3 P4 : : : Pn-1 Pn RAM Command line Arguments Stack HOLE Heap .BSS(Uninitialized Data segment) Initialized data Segment Code Segment Data Segment Parameter List Return Address Local Variables StackMemory Layout
  • 9. Various Passing Mechanisms Pass by Value Pass by reference ● This method copies the actual value of an argument into the formal parameter of the function. ● In this case, changes made to the parameter inside the function have no effect on the actual argument. ● This method copies the address of an argument into the formal parameter. ● Inside the function, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the argument.
  • 12. Pass by value & Pass by reference DIY Problem 1: Write a function to swap two integers passed from main function. Problem 2: Write a function to perform both sum & product of two different integers passed from main function.
  • 14. Ingnoring the function's return value  In C tradition, you can choose to ignore to capture the  return value from a method: ● Function read_int returning an int And collecting in variable i in the main function. ● Main function ignoring the return value.
  • 16. Introduction ● An array is a collection of data of similar data type. ● Example: If we want to store the ages of 5 different people, then we can use array instead of using 5 different variables. ● The mory alloaction will be contiguos. ● A specific element in an array is accessed by an index.
  • 17. Array: Declaration Syntax type arrayName [ SIZE ]; Example To declare an array to store ages of 5 people int age[ 5 ]; Total Memory Total Memory = SIZE * sizeof(dataType) = 5 * sizeof( int ) // Assuming sizeof(int) = 4 = 5 * 4 = 20 bytes
  • 18. Array: Definition Example To declare an array to store ages of 5 people int age[ 5 ] = {10, 20, 30, 40, 50}; Memory Allocation 10 20 30 40 50 age[0] age[4] age[3] age[2] age[1] 100 104 108 112 116  DIY : Write a program to add all the elements of the array.
  • 19. Array: Passing to function DIY: WAF to sort the elements of the array in asc / des order.
  • 20. Returning the array from the function
  • 21. Array: Passing to function Static keyword is used to retain the values between the function  calls
  • 23. Variadic Functions: Introduction ● Variadic functions can be called with any number of trailing arguments. For example, printf(), scanf() are common variadic funtions ● Variadic functions can be called in the usual way with individual arguments. syntax return_type function_name(parameter list, ...);
  • 24. Variadic Functions: How are defined & used Defining and using a variadic function involves three steps: step 1: Variadic functions are defined using an ellipsis (‘
’) in the argument list, and using special macros to access the variable arguments. For example, step 2: Declare the function as variadic, using a prototype with an ellipsis (‘
’), in all the files which call it. Step 3: Call the function by writing the fixed arguments followed by the additional variable arguments.
  • 25. Variadic Functions: Arguments access macros ● Descriptions of the macros used to retrieve variable arguments. ● These macros are defined in the header file stdarg.h Type/ Macros Description va_list The type va_list is used for argument pointer variables va_start This macro initializes the argument pointer variable ap to point to the first of the optional arguments of the current function; last-required must be the last required argument to the function va_arg The va_arg macro returns the value of the next optional argument, and modifies the value of ap to point to the subsequent argument. Thus, successive uses of va_arg return successive optional arguments va_end This ends the use of ap
  • 28. Recursive Function ● Function calling itself Steps: 1. Identification of the base case. 2. Writing the recursive case. Example Factorial of a number n ! 1 n = 0 (Base case) n * (n – 1) ! n > 0 (Recursive case)
  • 31. Stay connected About us: Emertxe is India’s one of the top IT finishing schools & self learning kits provider. Our primary focus is on Embedded with diversification focus on Java, Oracle and Android areas Branch Office: Corporate Headquarters: Emertxe Information Technologies, Emertxe Information Technologies, No-1, 9th Cross, 5th Main, 83, Farah Towers, 1st Floor, Jayamahal Extension, MG Road, Bangalore, Karnataka 560046 Bangalore, Karnataka - 560001 T: +91 809 555 7333 (M), +91 80 41289576 (L) E: training@emertxe.com https://www.facebook.com/Emertxe https://twitter.com/EmertxeTweet https://www.slideshare.net/EmertxeSlides