C Programming -Lecture 8 : Functions
How to write function
We now printf, scanf, etc., used functions. Now we will learn to create your own functions.
Suppose we want to print two lines
#include "stdio.h"
void main ()
Now, if we want to write two lines of up to 3 times if you wish these lines, then we can write the two 6-lane. We will not function if you use a lot cleaner. For a name to any function. We have just drowned printhello name. The statement that we are happy to be able to enter the block.
void printhello ()
Now that this function will not work if we want to have it at any time, just call it to function. We just write the name of the function for function calls Rabies
printhello ();
We therefore see that the whole program
#include "stdio.h"
void print hello ()
{
printf ( Wrong)
printf (Code
}
void main ()
print hellow()
print hellow ();
}
Thus, any work we do over and over again is that the function can make it down once. We can only move through text, type in the job after repeated.
Function return
Now I return function. A function to return any time we can get out of the function by using keywords. This program will be moved to the control from the function call.
Suppose we have a function f1 from which we want to return the number 35
int f1 ()
{
// [Do something]
return 35;
}
Now we have the function main will call. A number of these phammanata returns. If we want to keep ekata variable number to the returns of an = sign, then we must use it can be helpful to write
r = f1 ();
Thus we return to the values ??of a variable can be any function.
Let the program we yraro
int f1 ()
{
// [Do something]
return 35;
}
void main ()
{
int r;
r = f1 ();
}
Function Parameters
We use a lot of task functions. Suppose a function of this,
f (x) = 2x + 3
Now if x = 5 then f (x) = 13 would be. Again, if x = 3 , then f (x) = 9 will be.
Here is a function parameter, which is x. We see another function, which has two parameters x and y
f (x, y) = 2x + 3y
Now, if x = 2, y = 3 then f (2,3) = 13 would be. Again, if x = 1, y = 1, then f (x, y) = 5 will be.
So our function, we can use one or more parameters.
Now we see how the top of the C programming language to write a modest attempt phansanaguloke
First, f (x) = 2x + 3 function in C language such as translation kari
int f (int x)
{
return 2 * x + 3;
}
We see the same amount of metamuti function language such as C can be expressed. We've used the symbol = return. = Marks the return refers to the task. The parameters and return type of the function of the type of language such as C should be.
Now we have f (x, y) = 2x + 3y function translation kari
int f (int x, int y)
{
return 2 * x + 3y;
}
Thus, we can add any number of function parameters.
Function returns one more time
Let the function once again we return
int f1 (int n)
{
if (n == 0)
return 0;
if (n == 1)
return 1;
return n * n;
}
void main ()
{
int r = 5;
int q = f1 (r);
}
If we call the function f1 to 5 parameters, then the two will not work, and if none of the finish line and the main function will return 25 to 25 q value.
But if we call the function f1 of the main r = 0 at first if tahalai 0 returns TRUE, because of the conditions and the main function of q value to 0. The goal of the program is the function that returns once come out of, and control of the program from which the call was coming back.
Function parameters byval
We write a function that will return a number square.
int square (int number)
{
number = number * number;
return number;
}
void main ()
Now, the main function has been assigned to a variable value of n 3. The square has been the function call. The first line changes the value of the parameter of the function square num 9, and the return was 9. The main function of the value of r will be 9. But the value of n will not change. Thus, when we'll send a parameter a function in which the function will change the value from which the call was made, but there should not be any change in the quality of the variables used such parameters as we do byval parameters. Console 3 9 will print.
Function parameters byref
void main ()
Now the console 9 9 will print.
How to write function
We now printf, scanf, etc., used functions. Now we will learn to create your own functions.
Suppose we want to print two lines
#include "stdio.h"
void main ()
Now, if we want to write two lines of up to 3 times if you wish these lines, then we can write the two 6-lane. We will not function if you use a lot cleaner. For a name to any function. We have just drowned printhello name. The statement that we are happy to be able to enter the block.
void printhello ()
Now that this function will not work if we want to have it at any time, just call it to function. We just write the name of the function for function calls Rabies
printhello ();
We therefore see that the whole program
#include "stdio.h"
void print hello ()
{
printf ( Wrong)
printf (Code
}
void main ()
print hellow()
print hellow ();
}
Thus, any work we do over and over again is that the function can make it down once. We can only move through text, type in the job after repeated.
Function return
Now I return function. A function to return any time we can get out of the function by using keywords. This program will be moved to the control from the function call.
Suppose we have a function f1 from which we want to return the number 35
int f1 ()
{
// [Do something]
return 35;
}
Now we have the function main will call. A number of these phammanata returns. If we want to keep ekata variable number to the returns of an = sign, then we must use it can be helpful to write
r = f1 ();
Thus we return to the values ??of a variable can be any function.
Let the program we yraro
int f1 (){
// [Do something]
return 35;
}
void main ()
{
int r;
r = f1 ();
}
Function Parameters
We use a lot of task functions. Suppose a function of this,
f (x) = 2x + 3
Now if x = 5 then f (x) = 13 would be. Again, if x = 3 , then f (x) = 9 will be.
Here is a function parameter, which is x. We see another function, which has two parameters x and y
f (x, y) = 2x + 3y
Now, if x = 2, y = 3 then f (2,3) = 13 would be. Again, if x = 1, y = 1, then f (x, y) = 5 will be.
So our function, we can use one or more parameters.
Now we see how the top of the C programming language to write a modest attempt phansanaguloke
First, f (x) = 2x + 3 function in C language such as translation kari
int f (int x)
{
return 2 * x + 3;
}
We see the same amount of metamuti function language such as C can be expressed. We've used the symbol = return. = Marks the return refers to the task. The parameters and return type of the function of the type of language such as C should be.
Now we have f (x, y) = 2x + 3y function translation kari
int f (int x, int y)
{
return 2 * x + 3y;
}
Thus, we can add any number of function parameters.
Function returns one more time
Let the function once again we return
int f1 (int n)
{
if (n == 0)
return 0;
if (n == 1)
return 1;
return n * n;
}
void main ()
{
int r = 5;
int q = f1 (r);
}
If we call the function f1 to 5 parameters, then the two will not work, and if none of the finish line and the main function will return 25 to 25 q value.
But if we call the function f1 of the main r = 0 at first if tahalai 0 returns TRUE, because of the conditions and the main function of q value to 0. The goal of the program is the function that returns once come out of, and control of the program from which the call was coming back.
Function parameters byval
We write a function that will return a number square.
int square (int number)
{
number = number * number;
return number;
}
void main ()
Now, the main function has been assigned to a variable value of n 3. The square has been the function call. The first line changes the value of the parameter of the function square num 9, and the return was 9. The main function of the value of r will be 9. But the value of n will not change. Thus, when we'll send a parameter a function in which the function will change the value from which the call was made, but there should not be any change in the quality of the variables used such parameters as we do byval parameters. Console 3 9 will print.
Function parameters byref
void main ()
Now the console 9 9 will print.

No comments: