SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programmingClaus Wu
 

La actualidad más candente (20)

Embedded C
Embedded CEmbedded C
Embedded C
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 
Linux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platformLinux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platform
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
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
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Embedded Operating System - Linux
Embedded Operating System - LinuxEmbedded Operating System - Linux
Embedded Operating System - Linux
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
Micro-controllers (PIC) based Application Development
Micro-controllers (PIC) based Application DevelopmentMicro-controllers (PIC) based Application Development
Micro-controllers (PIC) based Application Development
 
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
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
Linux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platformLinux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platform
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programming
 

Destacado

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_-
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
 

Destacado (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
 

Similar a C Programming - Refresher - Part II

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
 

Similar a 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
 

Más de Emertxe Information Technologies Pvt Ltd

Más de 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
 

Último

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
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
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 

Último (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
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
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

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