100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Lecture notes Programming in C (EST102) £8.09
Add to cart

Lecture notes

Lecture notes Programming in C (EST102)

 0 purchase
  • Module
  • Institution

Programming in C , S2 , MODULE 4

Preview 3 out of 26  pages

  • June 25, 2024
  • 26
  • 2023/2024
  • Lecture notes
  • Prof. sumith
  • All classes
avatar-seller
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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller aqsas. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for £8.09. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

68175 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy revision notes and other study material for 15 years now

Start selling
£8.09
  • (0)
Add to cart
Added