HI TO EVERY ONE AND ADVANCE IN THANKS FOR YOUR CONSTANT SUPPORT AND TODAY, I WOULD LIKE TO DICUSS ABOUT FUNCTIONS AND ITS DECLARATION AND PROTOTYPES OF FUNCTIONS AND USES.

1)WHAT IS A FUNCTION??
ANS:A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions.
From above  it is concluded that it is set of tasks performed in that program is known as functions.
2)WHAT ARE THE USES OF USING FUNCTIONS IN C??
ANS: The use of these functions is that  a program can be divided into simpler forms or smaller ones; and program can easily be written because while we are performing a subsequently large computing task then there is a necessity of using these functions. I hope , every understood the uses of functions for any more or useful information if have guys then please comment below, which will be beneficial for others guys.
3) HOW TO DEFINE THESE FUNCTIONS ??
ANS:  return_type function_name(argument_declaration){
                      statements
                   }

 Function Body: The function body contains a collection of statements that define what the function does.

Function Name: This is the actual name of the function. The function name and the parameter list together constitute the function signature.










----------------------------------------------------------------------------------------------------------------------------------------------------
4) WHAT IS FUNCTION PARAMETERS AND ARGUMENTS ??
ANS: C functions generally exchange their information using parameters and its arguments. Here , the parameter refers to any type of   declaration in parenthesis is know as parameter. Here , the parameters of the function are written in closed brackets that is ( )-->parenthesis brackets . Where as arguments are nothing but it refers to the expression within the parenthesis of the function call . Here, the arguments are passed by a value , and parameter receives the copy of that argument value  and not it's address.
-----------------------------------------------------------------------------------------------
5) WHAT IS CALLING FUNCTION AND CALLED FUNCTION ??

ANS: calling function in general it is main() function and where as , the called function in general is subtasks or group of tasks which are performed in that is a called function.

CALLING A FUNCTION :

When a program calls a function, the program control is transferred to the called function. A called function performs a defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns the program control back to the main program.The point at which the function is being invoked or called is known as the calling function. The function which is being executed due to the function call is known as the called function

EXAMPLE :
IN THIS EXAMPLE I MAKE U GUYS TO MORE AWARE OF THE CALLING FUNCTION AND CALLED FUNCTION.
#include<stdio.h>  /* function definition for addition () */
int addition(int a,int b){
int s;           /* declare local variable inside the function */
s=a+b;      
return s;     /* above return type of function is int . Therefore , the return value is    an    integer */
}
int main(){
int sum;
/* call function addition to add , the return value from function is assigned to the variable sum */
sum=addition(3,4); /* even numbers can be declared or another variables can be declared */
printf("s=%d\n",sum);
return 0;
}
output:
s=7
IF WE PLACE , addition(3.0,4.0) gets converted into integer because the actual argument is an integer.
NOTE:
if the expression following the return statement has a type different from the function in which appears, the value gets converted here.
for example:
int func(int a,int b){
double d;
/*----------- */
d=4.6;
return d;
}
from above example we can observe that the function func() is an int. Eventhough , the expression in the return statement is double type it will get type casted implicitly, that means it will get converted into integer (directly or without permission).Therefore, the output of the program is 4(4.6-->4).  
I hope, everything about this topic is clear that what is calling function and called function and declarations, if u have any doubts I am ready to clarify u r doubts ,please comment below.

FUNCTION PROTOTYPES :

example:
#include<stdio.h>
#define M_G 9.81  /* gravitational acceleration constant 'g' */

/*function prototypes for force() and accel() */
double force(double t);
double accel(double t, double mu, double m);
/* main() function appears before the definitions of called function force() and    accel() are defined */
int main(){
double a, mu , m, t;
int I;
mu=0.2;
m=5.0;
t=2.0;
a=accel ( t, mu, m);  // here we are calling the function accel() that is the main() is always considered as called functions */
printf("acceleration a = %f (m/s^2)\n",a);
return 0;
}
double force(double t){
double p;
p = 4*(t-3)+20;
return p;
}
double accel(double t, double mu, double m){
double a, p;
p = force(t);  // here in this accel() calling function and force() is called function.
a= (p-mu*m*M_G)/m;
return a;
}
-----------------------------------------------------------------------------------------------
5) WHAT IS THE CALL-BY-VALUE AND CALL-BY-REFEENCE ???
ANS: we know that arguments are of two types:
a). call-by-value.
b).call-by-reference.


Before, discussing about the above two terms I would like to discuss about the actual and formal arguments.
-----------------------------------------------------------------------------------------------
EXAMPLE
#include<stdio.h>
int addtwo(int , int );   /* this the function prototype */
int main(){
int x, y, sum;
sum=addtwo(x, y); // main() is an calling function.
printf("the sum of %d and %d is : %d", x ,y, sum);
return 0;
}
int addtwo(int a, int b){
return a+b;  // called function
}
here, x, y are the actual arguments invoked in the main function that is why these are called as the actual arguments.
and where as, the a, b are the formal arguments ,here it keeps of track of it. The
formal arguments are the copy of the actual arguments . A change in formal arguments will not reflect the actual arguments.
-----------------------------------------------------------------------------------------------
Now comes to the matter, In the call-by-reference method , however, the address  of an argument is copied into the formal parameter of an function . Inside the called function, the address is used to access the actual argument used in calling function.
-----------------------------------------------------------------------------------------------


I HOPE ,I EXPLAINED CLEARLY THE TOPIC ABOUT FUNCTIONS.SO, ONE'S AGAIN THANKS TO  EVERYONE WHO EVER VISITING MY BLOG.IN NEXT SESSION I WILL EXPLAIN ABOUT RECURSION AND FEW PROBLEMS ON IT AND POINTERS.

-----------------------------------*THE  END*---------------------------------------------
































Protected by Copyscape

Comments

Popular posts from this blog

BIRTHDAY PARTY

spoj CPTTRN1 - Character Patterns (Act 1) solution

ROY AND PROFILE PICTURE