Tuesday, March 1, 2016

Functions with Multiple Parameters

functions can have more than one argument. In that case the function definition, prototype and the function call must have arguments separated by commas. Consider the simple program where the function 'print_bigger' accepts two arguments.
  1. #include<stdio.h>
  2. void print_bigger(int first, int second);
  3.  
  4. void main()
  5. {
  6. print_bigger(15, 27);
  7. }
  8.  
  9. void print_bigger(int first, int second)
  10. {
  11. if(first > second)
  12. {
  13. printf("%d is bigger", first);
  14. }
  15. else if(first == second)
  16. {
  17. printf("both number are same");
  18. }
  19. else
  20. {
  21. printf("%d is bigger", second);
  22. }
  23. }
Here the function 'print_bigger' takes two arguments and prints the number which is bigger than the other or prints "both number are same" if both arguments have the same value.

User Defined Functions and Library Functions

We have already seen both user defined and library functions. User defined functions are the functions that are defined by the programmer and not provided by C. The library functions or system defined functions are provided by C libraries, like 'printf''scanf' etc.
There are a lot of library functions available in C. The standard C library provides functions like'printf', 'scanf', 'putc', 'getc', 'puts', 'gets' etc. Functions like 'toupper', 'tolower', 'isalpha' etc., have their definitions in header file 'ctype.h''sin', 'cos', 'sqrt' have definition in 'math.h' file.

No comments: