Functions in C and C++
Talk to a Teacher
http://spoken-tutorial.org
National Mission on Education through ICT
http://sakshat.ac.in
Ashwini R Patil
IIT Bombay
4 May 2012
Ashwini R Patil Functions in C and C++
Learning Objectives
Ashwini R Patil Functions in C and C++
Learning Objectives
I What is a function
Ashwini R Patil Functions in C and C++
Learning Objectives
I What is a function
I Syntax of a function
Ashwini R Patil Functions in C and C++
Learning Objectives
I What is a function
I Syntax of a function
I Significance of return statement
Ashwini R Patil Functions in C and C++
Learning Objectives
I What is a function
I Syntax of a function
I Significance of return statement
I Through examples
Ashwini R Patil Functions in C and C++
Learning Objectives
I What is a function
I Syntax of a function
I Significance of return statement
I Through examples
I Some common errors and their solutions
Ashwini R Patil Functions in C and C++
System Requirements
Ashwini R Patil Functions in C and C++
System Requirements
I Ubuntu OS v. 11.10
Ashwini R Patil Functions in C and C++
System Requirements
I Ubuntu OS v. 11.10
I gcc and g++ Compiler v. 4.6.1
Ashwini R Patil Functions in C and C++
Introduction to Functions
Ashwini R Patil Functions in C and C++
Introduction to Functions
I A function is a self-contained program
executing a specific task
Ashwini R Patil Functions in C and C++
Introduction to Functions
I A function is a self-contained program
executing a specific task
I Every program consists of one or more
functions
Ashwini R Patil Functions in C and C++
Introduction to Functions
I A function is a self-contained program
executing a specific task
I Every program consists of one or more
functions
I Once executed the control will be
returned back from where it was
accessed
Ashwini R Patil Functions in C and C++
Syntax for Function
Ashwini R Patil Functions in C and C++
Syntax for Function
I Syntax
Ashwini R Patil Functions in C and C++
Syntax for Function
I Syntax
I ret-type fun-name(parameters)
Ashwini R Patil Functions in C and C++
Syntax for Function
I Syntax
I ret-type fun-name(parameters)
Ashwini R Patil Functions in C and C++
Syntax for Function
I Syntax
I ret-type fun-name(parameters)
OR
Ashwini R Patil Functions in C and C++
Syntax for Function
I Syntax
I ret-type fun-name(parameters)
OR
I ret-type fun-name( )
Ashwini R Patil Functions in C and C++
Summary
I Function
I Syntax of function
I Function without arguments
I eg. void add()
I Function with arguements
I eg. int add(int a, int b)
Ashwini R Patil Functions in C and C++
Assignment
I Write a program to calculate the square
of a number
Ashwini R Patil Functions in C and C++
About the Spoken Tutorial Project
I Watch the video available at
http://spoken-tutorial.org
/What is a Spoken Tutorial
I It summarises the Spoken Tutorial project
I If you do not have good bandwidth, you
can download and watch it
Ashwini R Patil Functions in C and C++
Spoken Tutorial Workshops
The Spoken Tutorial Project Team
I Conducts workshops using spoken
tutorials
I Gives certificates to those who pass an
online test
I For more details, please write to
contact@spoken-tutorial.org
Ashwini R Patil Functions in C and C++
Acknowledgements
I Spoken Tutorial Project is a part of the
Talk to a Teacher project
I It is supported by the National Mission
on Education through ICT, MHRD,
Government of India
I More information on this Mission is
available at:
http://spoken-tutorial.org
/NMEICT-Intro
Ashwini R Patil Functions in C and C++