Session 7

Page 1

Session 7

Functions (Lab Guide)

Objectives At the end of this chapter, you will be able to:  Define and call function  Use of parameters in function Part I – For the first 1 Hour and 30 Minutes: 1.1

Functions As we already know, a function is a self-contained block of statements that perform a task of some kind. In this chapter, let us focus on how to create and use functions.

1.1.1

Define a function A function is defined with a function name, is followed by a pair of curly braces in which one or more statements may be present. For example, argentina() { statement 1; statement 2; statement 3; }

1.1.2

Calling a function A function can be called from a main program by stating its name followed by a pair of braces and a semi-colon. For example, argentina(); Now, Let us look at the complete program. 1. Invoke the editor in which you can type the C program. 2. Create a new file. 3. Type the following code : #include<stdio.h> void main() { printf(“\n I am in main”); italy(); brazil();

Functions

59


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.