0% found this document useful (0 votes)
65 views6 pages

6.function Prototypes

The document discusses four categories of functions in C: 1. Functions with no arguments and no return values, where data is processed within the function but not passed in or out. 2. Functions with arguments but no return values, where data is passed into the function for processing. 3. Functions with arguments and return values, allowing two-way data transfer between caller and function. 4. Functions with no arguments but return values, where data is returned from the function but not passed in. Examples are provided for each category.

Uploaded by

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

6.function Prototypes

The document discusses four categories of functions in C: 1. Functions with no arguments and no return values, where data is processed within the function but not passed in or out. 2. Functions with arguments but no return values, where data is passed into the function for processing. 3. Functions with arguments and return values, allowing two-way data transfer between caller and function. 4. Functions with no arguments but return values, where data is returned from the function but not passed in. Examples are provided for each category.

Uploaded by

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

SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35

(An Autonomous Institution)


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Function Prototypes / Categories of functions

• Function with no arguments and no return values.


• Function with arguments and no return values.
• Function with arguments and return values.
• Function with no arguments and with return values.

1. Function with no arguments and no return values


In this prototype, no data transfers takes place between the calling
function and the called function. They read data values and print result in the
same block.

Example :
#include <stdio.h>
#include<conio.h>
void main() //calling function
{
void add(void);
add();
}

void add() //called function


19ITT101- Programming in C & DS By M.Karthick AP/CSE
SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

{
int a,b,c;
printf("\nEnter two number:");
scanf("%d%d",&a,&b);
c=a+b;
printf("\nSum is:%d",c);
}

Output:
Enter two number:3
4
Sum is:7

2. Function with arguments and no return values


In this prototype, data is transferred from the calling function to called
function.
The called function receives some data from the calling function and does
not send back any values to the calling functions. It is a one way data
communication.

Example:

19ITT101- Programming in C & DS By M.Karthick AP/CSE


SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

#include <stdio.h>
#include<conio.h>
void main()
{
int a,b;
void add(int,int);
printf("\nEnter two number:");
scanf("%d%d",&a,&b);
add(a,b);
}
void add(int x,int y) //function with arguments
{
int z;
z=x+y;
printf("\nSum is:%d",z);
}
Output
Enter two number:2
4
Sum is:6

3. Function with arguments and return values


In this prototype, the data is transferred between the calling
function and called function.
The called function receives some data from the calling function and send
back a value return to the calling function. It is a two way data
communication.

19ITT101- Programming in C & DS By M.Karthick AP/CSE


SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Example
#include <stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
int add(int,int);
printf("\nEnter two number:");
scanf("%d%d",&a,&b);
c=add(a,b);
printf("\nSum is:%d",c);
}
int add(int x,int y)
{
int z;
z=x+y;
return(z);
}

Output
Enter two number:6
7
Sum is:13

19ITT101- Programming in C & DS By M.Karthick AP/CSE


SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

4. Function with no arguments and with return values

The calling function cannot pass any arguments to the called function
but the called function may send some return value to the calling function. It is
a one way data communication

Example:
#include <stdio.h>
#include<conio.h>
void main()
{
int add(),d;
d=add();
printf("\nSum is:%d",d);
}

19ITT101- Programming in C & DS By M.Karthick AP/CSE


SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

int add() //function wit no argument


{ int a,b,c;
printf("\nEnter two number:");
scanf("%d%d",&a,&b);
c=a+b;
return(c);
}

Output
Enter two number:5
8
Sum is:13

Note:

 If the return data type of a function is “void”, then, it can‟t return any
values to the calling function.
 If the return data type of the function is other than void such as “int, float,
double etc”, then, it can return values to the calling function.

19ITT101- Programming in C & DS By M.Karthick AP/CSE

You might also like