Академический Документы
Профессиональный Документы
Культура Документы
A function may have more than one return statement this situation
arises when the value returned is based on certain conditions. For example
if(x<=0)
return(0);
else
return(1);
If the function having two return statements also but it returns only
one value at a time.
The user define function may be classified as three ways based on the
formal arguments passed and return type
1) Functions with no arguments and no return value
A function is invoked without passing any formal arguments
from the calling portion of a program and also the calling function
does not return any value to the called function.
#include<stdio.h>
void display();
main()
{
void display();
}
void display()
{
printf(“Hello\n”);
printf(“How r u”);
}
OUTPUT: Hello
How r u
2) Functions with arguments and no return values
This type of function passes some formal arguments to a function but
the function does not return any value to the caller function.
#include<stdio.h>
#include<conio.h>
void square(int);
void main()
{
int n;
clrscr();
printf(“Enter a value\n”);
scanf(“%d”,&n);
square(n);
getch();
}
void square(int x)
{
int s;
s=x*x;
printf(“The square of %d is %d”,x,p);
}
STORAGE CLASSES IN C:
To fully define a variable one needs to mention not only its ‘type’ but
also its ‘storage class’. In other words, not only do all variables have a data
type, they also have a storage class.
A variable’s storage class tells us:
1) Where the variable would be stored (either in memory or registers)
2) What will be the initial value of the variable, if initial value is not
specifically assigned (i.e. the default initial value).
3) What is the scope of the variable; i.e. in which functions the value of the
variable would be available.
4) What is the life of the variable i.e. how long would the variable exist.
There are four storage classes in C:
n) Automatic Storage Class
o) Register Storage Class
p) Static Storage Class
d)External Storage Class