0% found this document useful (0 votes)
32 views17 pages

Lecture 6

This document discusses functions in C programming. It defines two types of functions - built-in/library functions which are predefined, and user-defined functions which must be programmed by the user. Functions are modular units that perform specific tasks. A function prototype declares the return type, number of parameters, and parameter types. Functions have a definition which implements the requirements, and can be called from other parts of the code.

Uploaded by

Rinku Rinku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views17 pages

Lecture 6

This document discusses functions in C programming. It defines two types of functions - built-in/library functions which are predefined, and user-defined functions which must be programmed by the user. Functions are modular units that perform specific tasks. A function prototype declares the return type, number of parameters, and parameter types. Functions have a definition which implements the requirements, and can be called from other parts of the code.

Uploaded by

Rinku Rinku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

CSE-125

Computer Programming &


Engineering Analysis

Lecture: 6
Functions
Avishek Das

Department of CSE
CUET
FUNCTIONS
➢Functions in C, can be classified into two types
1. Built-in/Library and
2. User-defined.
Library functions – already defined in header file. Example –
printf(), scanf(), sqrt()
User-defined – needed to be programmed by user. Example –
main(), other functions.
➢Function, also called subprogram that carries out some
specific and well-defined task.

17/11/2022 Department of CSE, Chittagong University of Engineering & Technology 2


➢Modular programming – process of organizing a large program into
small, independent program segments called modules, that are
separately named and individually called programmable units
➢Characteristics -
➢Each module should do only one thing.
➢Communication between module is allowed only by a calling module.
➢A module can be called by one and only one higher module.
➢No communication can take place directly between modules that do not have
calling-called relationship.
➢All modules are designed as single-entry, single-exit systems using control
structures.

17/11/2022 Department of CSE, Chittagong University of Engineering & Technology 3


Function Prototype

return_type function_name (type parameter-name1, type parameter-name1 .….. type parameter-nameN )


{
function body…
Return_Value
}

A prototype declares three attributes associated with a function:


1. Its return type
2. The number of its parameters
3. The type of its parameters

17/11/2022 Department of CSE, Chittagong University of Engineering & Technology 4


17/11/2022 Department of CSE, Chittagong University of Engineering & Technology 5
STRUCTURE OF A FUNCTION

/Arguments

17/11/2022 Department of CSE, Chittagong University of Engineering & Technology 6


USER-DEFINED FUNCTIONS
➢3 elements related to function –
➢Function definition – an independent program module that is specially
written to implement the requirements of the function.
➢Function call – to use it, we need to call it at a required place of the program.
Functions that call the other functions, is called calling function.
➢Function declaration – any functions that are used later should be declared
specifically.
➢Function definition should have –
➢Function name
➢Function type Function header
➢List of parameters
➢Local variable declaration
➢Functions statements Function body
➢Return statement

17/11/2022 Department of CSE, Chittagong University of Engineering & Technology 7


DECLARING PROTOTYPE OF A FUNCTION

17/11/2022 Department of CSE, Chittagong University of Engineering & Technology 8


A simple Function for
number addition
Function for Factorial
Function to find maximum between numbers
Function to Print Odd/Even
Function to Return Odd/Even
Function to find area of triangle
Function to find area of triangle
Array in
Function
Array in
Function

You might also like