Concept of function in C?
quest1 Define function?
A function is a module or block of program code which deals with a particular task. Making functions is a way
of isolating one block of code from other independent blocks of code.
quest 2Methods of passing in functions?
There are two ways to pass parameters to a function:
- Pass by Value: mechanism is used when you don’t want to change the value of passedparamters. When parameters are passed by value then functions in C create copies of the passed in variables
and do required processing on these copied variables.
- Pass by Reference mechanism is used when you want a function to do the changes in passedparameters and reflect those changes back to the calling function. In this case only addresses of the
variables are passed to a function so that function can work directly over the addresses.
quest 3 Example of pass by value?
#include <stdio.h> void swap( int p1, int p2 ); int main() { int a = 10; int b = 20; printf("Before: Value of a = %d and value of b = %dn", a, b ); swap( a, b ); printf("After: Value of a = %d and value of b = %dn", a, b ); } void swap( int p1, int p2 ) { int t; t = p2; p2 = p1; p1 = t; printf("Value of a (p1) = %d and value of b(p2) = %dn", p1, p2 ); }
quest 4 Example of pass by reference?
#include <stdio.h> void swap( int p1, int p2 ); int main() { int a = 10; int b = 20; printf("Before: Value of a = %d and value of b = %dn", a, b ); swap( a, b ); printf("After: Value of a = %d and value of b = %dn", a, b ); } void swap( int p1, int p2 ) { int t; t = p2; p2 = p1; p1 = t; printf("Value of a (p1) = %d and value of b(p2) = %dn", p1, p2 ); }
quest 5 concept of return in functions?
A return keyword is used to return a value and datatype of the returned value is specified before the
name of function. In this case function returns total which is int type. If a function does not
return a value then void keyword can be used as return value.
quest 6 what is function defination?
When a function is defined at any place in the program then it is called function definition. At the time of definition of a function actual logic is implemented with-in the function.
quest 7 Some features of function in c?
1) Reusability of Code : Means Once a Code has Developed then we can use that Code
any Time.
2) Remove Redundancy: Means a user doesn’t need to Write Code Again and Again.
3) Decrease Complexity: Means a Large program will be Stored in the Two or More
Functions. So that this will makes easy for a user to understand that Code.
Tell us Your Queries, Suggestions and Feedback
6 Responses to Concept of function in C?
« RISC / CISC Pakistan’s brutal attack at LoC(Line of Control) »
Concept of functions is very much important for understanding C programming language. This is the building block for any software project.
Function implementation and its reusability has helped C to be one of most accepted language
Functions are very important part of C programming & help in constructing complex programs.
C language has different no of functions and they are used differently at various points…this article gives the idea of the usage of the functions properly in the programming
as all we know that C is a basic language..check it and make you aware about different function used in C..
The write up deals with the varying uses of the functions available in C!