|
Used to break problem down to small, bite sized pieces
|
|
Have an optional type of return value, a name and optional arguments
|
|
Functions return at most, ONE value
|
|
Functions must be prototyped or declared before usage
|
#include<stdio.h>
void interchange(int *num1,int *num2)
{
int temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
}
int main() {
int num1=50,num2=70;
interchange(&num1,&num2);
printf("\nNumber 1 : %d",num1);
printf("\nNumber 2 : %d",num2);
return(0);
}
|
int
|
−2,147,483,648 to +2,147,483,647
|
|
unsigned int
|
0 to 4,294,967,295
|
|
int64
|
-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
|
|
Copy of original parameter is created & passed to the called function
|
|
Updates inside method will NOT affect the original value of the variable in the calling function
|
|
scope is limited, therefore it cannot alter values inside main function
|
#include<stdio.h>
void interchange(int number1,int number2)
{
int temp;
temp = number1;
number1 = number2;
number2 = temp;
}
int main() {
int num1=50,num2=70;
interchange(num1,num2);
printf("\nNumber 1 : %d",num1);
printf("\nNumber 2 : %d",num2);
return(0);
}
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.