Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Lecture notes Programming in C (EST102)

Rating
-
Sold
-
Pages
26
Uploaded on
25-06-2024
Written in
2023/2024

Programming in C , S2 , MODULE 4

Institution
Course

Content preview

PROGRAMMING IN C (EST102)


MODULE 4
Working with functions
Introduction to modular programming, writing functions, formal parameters,
actual parameters, Pass by Value, Recursion, Arrays as Function Parameters
structure, union, Storage Classes, Scope and life time of variables, simple
programs using functions




1

, MODULAR PROGRAMMING

Modular programming is the process of subdividing a computer program into
separate sub-programs.

Advantages

 Ease of Use: This approach allows simplicity, as rather than focusing on
the entire thousands and millions of lines code, access it in the form of
modules
 Programming errors are easy to detect: Minimizes the risks of
programming errors and also makes it easier to identify errors.

 Allows re-use of codes: A program module is capable of being re-used
in a program which minimizes the development of redundant codes

FUNCTION
A function is a group of statements that together perform a task. Every C
program has at least one function, which is main(), and can have additional
functions.

Types of Functions

There are two types of functions in C programming:
•Standard library functions
•User-defined functions
The main difference between these two categories is that library functions are
not required to be written by user whereas a user defined function has to be
developed by the user at the time of writing a program.

STANDARD LIBRARY FUNCTIONS
The standard library functions are built in functions. These functions are
defined in header files.
For example,
•printf () is a standard library function to send formatted output to the screen.
This function is defined in the stdio.h header file.
•sqrt () function calculates the square root of a number. The function is
defined in the math.h header file.
•strlen() function calculates the length of a given string. The function is defined
in the string.h header file.

2

, USER-DEFINED FUNCTIONS
User defined functions are functions that are defined by the user to do certain
specific task.

Advantages
•Program will be easier to understand, maintain and debug.
•Reusable codes that can be used in other programs
•Large program can be divided into smaller modules. Hence, a large project
can be divided among many programmers.

In order to make use of a function, three elements are required
1. Function declaration.
2. Function definition.
3. Function call.
Function Declaration
All functions in a c program must be declared, before they are invoked. A
function declaration (also known as function prototype) consists of four parts.
*Function type (return type).
*Function name.
*Parameter list.
*Terminating semicolon.

The general format of function declaration is:
Function-type function-name (parameter list);

In function declaration:
*The parameter list must be separated by commas.
*The parameter names do not need to be the same in the prototype
declaration and the function definition.
*Use of parameter names in the declaration is optional.
*If the function has no formal parameters, the list is written as void.
*The return type is optional, when the function returns int type data.
*The return type must be void if no value is returned.

Example: int addition (int a, int b);
int – function-type
addition – function-name
(int a, int b) -Parameters (arguments)

A prototype declaration may be placed in two places in a program.

3

Written for

Institution
Course

Document information

Uploaded on
June 25, 2024
Number of pages
26
Written in
2023/2024
Type
Class notes
Professor(s)
Prof. sumith
Contains
All classes

Subjects

$10.39
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
aqsas

Get to know the seller

Seller avatar
aqsas VKCET
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions