It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

Similar documents
C Programming Lecture V

& Technology. G) Functions. void. Argument2, Example: (Argument1, Syllabus for 1. 1 What. has a unique. 2) Function name. passed to.

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

UNIT 3 FUNCTIONS AND ARRAYS

Chapter 1 Getting Started Structured Programming 1

/* EXAMPLE 1 */ #include<stdio.h> int main() { float i=10, *j; void *k; k=&i; j=k; printf("%f\n", *j);

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

UNIT III (PART-II) & UNIT IV(PART-I)

Unit 7. Functions. Need of User Defined Functions

Multiple Choice Questions ( 1 mark)

Unit 3 Functions. 1 What is user defined function? Explain with example. Define the syntax of function in C.

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Chapter-13 USER DEFINED FUNCTIONS

Questions Bank. 14) State any four advantages of using flow-chart

Functions BCA-105. Few Facts About Functions:

Subject: Fundamental of Computer Programming 2068

Dynamic Memory Allocation

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

CSE 230 Intermediate Programming in C and C++ Functions

15 FUNCTIONS IN C 15.1 INTRODUCTION

CSE202-Lec#4. CSE202 C++ Programming

SUMMER 13 EXAMINATION Model Answer

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

SUHAIL T A

Q 1. Attempt any TEN of the following:

'C' Programming Language

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Computers Programming Course 12. Iulian Năstac

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

Lecture 9 - C Functions

Government Polytechnic Muzaffarpur.

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

ARRAYS(II Unit Part II)

Chapter 8 Character Arrays and Strings

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Strings and Library Functions

AMCAT Automata Coding Sample Questions And Answers

A PROBLEM can be solved easily if it is decomposed into parts. Similarly a C program decomposes a program into its component functions.

Lecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours?

String can be represented as a single-dimensional character type array. Declaration of strings

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

CSE 2421: Systems I Low-Level Programming and Computer Organization. Functions. Presentation C. Predefined Functions

Chapter 5 C Functions

Introduction. What is function? Multiple functions form a larger program Modular programming

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

User Defined Functions

Unit 4 Preprocessor Directives

b. array s first element address c. base address of an array d. all elements of an array e. both b and c 9. An array elements are always stored in a.

Computers Programming Course 5. Iulian Năstac

4. C++ functions. 1. Library Function 2. User-defined Function

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore

Model Viva Questions for Programming in C lab

Tutorial No. 2 - Solution (Overview of C)

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

Methods. Contents Anatomy of a Method How to design a Method Static methods Additional Reading. Anatomy of a Method

Functions. (transfer of parameters, returned values, recursion, function pointers).

Functions. Arash Rafiey. September 26, 2017

CHAPTER 4 FUNCTIONS. 4.1 Introduction

This exam is to be taken by yourself with closed books, closed notes, no calculators.

C Functions. 5.2 Program Modules in C

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

C Programming for Engineers Functions

Computer Language. It is a systematical code for communication between System and user. This is in two categories.

Computers Programming Course 10. Iulian Năstac

CS 108 Computing Fundamentals. October/November Array Bootcamp

C-LANGUAGE CURRICULAM

FUNCTIONS OMPAL SINGH

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

UNDERSTANDING THE COMPUTER S MEMORY

C Programming Basics. Ritu Arora Texas Advanced Computing Center June 19 th,

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION

Outline. Pointers arithme.c and others Func.ons & pointers

DECISION CONTROL AND LOOPING STATEMENTS

IV Unit Second Part STRUCTURES

Basics of Programming

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Fundamentals of Programming Session 8

BİL200 TUTORIAL-EXERCISES Objective:

Arrays in C. By Mrs. Manisha Kuveskar.

C programming basics T3-1 -

int marks[10]; // fixed size and fixed address No change in Memory address.

Full file at C How to Program, 6/e Multiple Choice Test Bank

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

Technical Questions. Q 1) What are the key features in C programming language?

CS 261 Data Structures. Introduction to C Programming

Downloaded from

LAB 6 FUNCTIONS I School of Computer and Communication Engineering

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE


Fundamentals of Programming. Lecture 3: Introduction to C Programming

CSCI 2132 Software Development. Lecture 17: Functions and Recursion

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

Functions. printf( %f cubed is %f,x,cube(x)); return 0; } return parameter type double cube(double var) { return (var*var*var);

SOLUTION FOR FUNCTION. 1) Write a program to display Hello 10 times. Create user-defined function message().

UNIT- I INTRODUCTION TO PROBLEM SOLVING TECHNIQUES

Transcription:

Functions

A number of statements grouped into a single logical unit are called a function. The use of function makes programming easier since repeated statements can be grouped into functions. Splitting the program into separate function make the program more readable and maintainable. It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

Contents : 1.Functions 2.Types of Functions : Built In Functions User Defined Functions 3.Function Call By Passing Value 4.Function Call By Returning Value 5.Function Call By Passing and Returning Value 6.Advantages 7.Recursion (Recursive Function)

The function is a self contained block of statements which performs a coherent task of a same kind. C program does not execute the functions directly. It is required to invoke or call that functions. When a function is called in a program then program control goes to the function body. Then, it executes the statements which are involved in a function body. Therefore, it is possible to call function whenever we want to process that functions statements. Types of functions : There are 2(two) types of functions as: 1. Built in Functions 2. User Defined Functions

Advantages of functions: It is easy to use. Debugging is more suitable for programs. It reduces the size of a program. It is easy to understand the actual logic of a program. Highly suited in case of large programs. By using functions in a program, it is possible to construct modular and structured programs.

1. Built in Functions :These functions are also called as 'library functions'. These functions are provided by system. These functions are stored in library files. e.g. scanf() printf() strcpy strlwr strcmp strlen strcat

1. User Defined Functions :The functions which are created by user for program are known as 'User defined functions'. Syntax: void main() // Function prototype <return_type><function_name>([<argu_list>]); // Function Call <function_name>([<arguments>]); // Function definition <return_type><function_name>([<argu_list>]); <function_body>;

#include<stdio.h> #include<conio.h> Void main() void text (void); text(); getch(); void text (void) Printf ( this is a demo program of function\n ); Printf ( Showing function calling in main program );

Program : /* Program to demonstrate function. #include <stdio.h> #include <conio.h> void add() int a, b, c; clrscr(); printf("\n Enter Any 2 Numbers : "); scanf("%d %d",&a,&b); c = a + b; printf("\n Addition is : %d",c); void main() void add(); add(); getch(); Output : Enter Any 2 Numbers : 23 6 Addition is : 29_

A function definition has two principal components: The function header and body of the function. The function header is the data type of return value followed by function name and (optionally) a set of arguments separated by commas and enclosed in parenthesis. Associated type to which function accepts precedes each argument. In general terms function header statement can be written as return_type function_name (type1 arg1,type2 arg2,..,typen argn) where return_type represents the data type of the item that is returned by the function, function_name represents the name of the function, type1,type2,,typen represents the data type of the arguments arg1,arg2,..,argn.

Example: Following function returns the sum of two integers. int add(int p,int q) return p+q; //Body of the function Here p and q are arguments. The arguments are called formal arguments or formal parameters, because they represent the name of the data item that is transferred into the function from the calling portion of the program. The corresponding arguments in the function call are called actual arguments or actual parameters, since they define the data items that are actually transferred. A function can be invoked whenever it is needed. It can be accessed by specifying its name followed by a list of arguments enclosed in parenthesis and separated by commas. e.g., add(5,10);