Skip to main content

Types of Function in C language return type function (argument) use

 Function use example:

1. Function with no argument (parameters) & no return value:

Basic example program addition

#include<stdio.h>
void add(void);
int main()
{
add();
}
void add()
{
int x,y=56,z=45;
x=y+z;
printf("ADD=%d",x);
}


Output are:

ADD=101

2. Function with no argument but return type:

Here called function is independent and are initialized . The value aren't passed by The calling function .Here the calling function and called function are communicated party with each other. 

Basic example program addition

#include<stdio.h>
int  add(void);
int main()
{
add();
}
int add(void)
{
int x,y=56,z=45;
x=y+z;
printf("ADD=%d",x);
}

Output are:

ADD=101


3. Function with argument but no return value

Here the function have argument so the calling function send date to the called function but called function dose not return value. Here the result obtained by the called function.
 
Basic example program addition

#include<stdio.h>
void add(int y,int z);
int main()
{
int a,b;
add(a,b);
}
void add(int y,int z)
{
int x;
y=56,z=45;
x=y+z;
printf("ADD=%d",x);
}

Output are:

ADD=101



4.Function with argument but return value

Here the calling function has the argument to pass to the called function and the called function returned value to the calling function.

Basic example program addition

#include<stdio.h>
int  add(int y,int z);
int main()
{
int a,b,c;
c=add(a,b);
printf("ADD=%d",c);
}
int add(int y,int z)
{
int x;
y=56,z=45;
x=y+z;
return x;
}

Output are:

ADD=101

Comments

Popular posts from this blog

Two dimensional array in C language or matrix program in c language

 Two dimensional arrays: 1.Two dimensional array is known as matrix. 2.An array with two subscripts is termed as two-dimensional array. 3.We know that a one dimensional array can store a row of elements, so a two-dimensional array enables us to store multiple roes of elements. The syntax of declaring a two-dimensional array is : Data-type array name[row][column]; For reading value : for(k=0;k<4;k++) { for(l=0;l<3;l++) { scanf("%d",&a[k][l]); } } For displaying value : for(k=0;k<4;k++) { for(l=0;l<3;l++) { printf("%d",a[k][l]); } printf("\n"); } Simple Matrix Program : #include"stdio.h" int main() { int a[3][3]; int k,l; printf("Enter the array elements: \n"); for(k=0;k<3;k++)  //for reading value// { for(l=0;l<3;l++) { printf("Enter a[%d][%d] :",k,l); scanf("%d",&a[k][l]); } } printf("\n\nMatrix are: \n"); for(k=0;k<3;k++)  //for displaying value...

Arithmetic program in C language || Calculator program in C language

  Calculator  program in C language .           First of all let us know its logic .how is this working . Now let's see it's process . In C language , %d is used to define it's integers and %f is used to define it's floats. In C language , the (+) sign is used as a plus , the (-) sign used as a minus , the (*) sign is used for multiplies and the (/) sign is used for division.                %0.2f it means any float value like 52.987 = 52.98.it show only 2 place of the decimal. PROGRAM                          /*ARITHMETIC PROGRAM IN C LANGUAGE*/ #include"stdio.h" int main() { float a,b,sum,sub,mult,div ; char sign; printf("SELECT ANY SIGN (+ - * / ) :"); scanf("%c",&sign); printf("ENTER THE FIRST NUMERIC VALUE:"); scanf("%f",&a); printf("ENTER THE SECOND NUMERIC VALUE:"); scanf("%f",&b); switch(sign) { case '+':...

(1+2+3.....n) Sum of n natural numbers, (1^2 + 2^2+3^2 ...... n^2)Sum square of n natural numbers, Sum cube of n natural numbers program in C language .

   Natural numbers program in c language                  H ow to make  (1+2+3.....n) Sum of n natural numbers, (1^2 + 2^2+3^2 ...... n^2)Sum square of n natural numbers, Sum cube of n natural numbers program in C language. Then today we will know about it through this program ...    Sum of n natural numbers            The Sum of n natural number formula are 1+2+3+....n = n(n+1)/2=(n^2+n)/2. The math.h header file is used in this program because the pow() function is defined in this header file. The function pow() syntax is double pow(double a , double b).   The double is a data type in c language and it's also defined as %lf for input. In this program add= (k+x)/2 where are k=n^2 ,x=n. /*SUM OF N NATURAL NUMBERS*/ #include"stdio.h" #include"math.h" int main() { double x,y=2; printf("ENTER THE NATURAL NUMBER:"); scanf("%lf",&x); double n=pow(x,y); int add=(n...