Professional Documents
Culture Documents
action
action
//statements
Return_type is the data type of the data thrown out by the function
Data is thrown out in the return statement
Return statement data type must match that of return_type
void is used if function returns no value
printf(“hey”);
Means the function can handle
char* cs
printf(“value is %d”, num);
Means the function can also handle
char*cs + list_of_names);
#include <stdio.h>
int a, b;
int c;
main()
{
printf(“Enter first whole number:”);
scanf(“%d”, &a);
printf(“Enter first whole number:”);
scanf(“%d”, &b);
c = a + b;
printf(“Total of two numbers is: = %d”, c);
}
action
void input()
{ printf(“Enter first whole number:”);
scanf(“%d”, &a);
printf(“Enter second whole number:”);
scanf(“%d”, &b);
}
void means the function is not throwing out a value
() means the parameter list is empty
The above is an example of a general purpose function.
}
main()
{
void add() input();
{ add();
//invoke display, and multiply
c = a + b; // what happens if you switch add() and input()?
} }
void addxy(int a) { }
void mult(int x)
{
y = x * 2;
printf(“value of y = ”, y);
}
action
int multxy()
{
b = x * y;
return b;
}
int main()
total times 3 = 15
{
printf("\n\n Initial total value = %d", total); Process returned 21 (0x15)
printName(); total *= 3; execution time : -0.000 s
printf("\n\n total times 3 = %d", total);
} Press any key to continue.
33 CUIT111 SEST, CUT 10/30/2020
Example 3: Function call by value