Functions in ‘C’ language are divided into two types, standard library functions and user defined functions or a programmer defined functions.
Standard Library functions
Standard library functions are pre-packaged functions or in-built functions of ‘C’The ‘C’ standard library provide a rich collection of functions for performing common mathematical calculations, string manipulations character manipulations, input/output and many other useful operations.List of the most common libraries and a brief description of the most useful functions is given below:stdio.h:I/O functions:getchar() returns the next character typed on the keyboardputchar() outputs a single character to the screenprintf() used to write functions to write I/O devicesscanf() used to read from I/O devicesstring.h: String functionsstrcat() concatenates a copy of str2 to str1strcmp() compares two stringsstrcpy() compares contents of str2 to str1ctype.h:Character functionsisdigit() returns non-0 if arg is digit 0 to 9islapha() returns non-0 if arg is a letter of the alphabetisalnum() retuns non-0 if arg is a letter or digitisslower() returns non-0 if arg is a lowercase letterisupper() returns non-0 if arg is uppercase lettermath.h: Mathematics functionsacos() returns arc cosine of argasin() returns arc sine of argatan() returns arc tangent of argcos() returns cosine of argexp() returns natural logarithm efabs() returns absolute value of numsqrt() returns square root of numtime.h: Time and Date functionstime() returns current calendar time of systemdifftime() returns difference in sec between two timesclock() returns number of system clock cycles since program executionstdlib.h: Miscellaneous functionsmalloc() provides dynamic memory allocation, covered in future sectionsreand() as already described previouslysrand() used to set the starting point for rand()
User defined functions
User defined functions are self-contained blocks of statements which are written by the user to compute or perform a task.They can be called by the main program repeatedly as per the requirement.
Uses of functions
They are very much useful when a block of statements has to be written/executed again and again.They are useful when program sizes are too large and complex.It works like a top-down modular programming technique, to solve a problem.They are also used to reduce the difficulties during debugging a program.The length of a source program can be reduced by using functions at appropriate places.It is easy to locate and isolate a faulty function for further investigations.A function can be used by many other programs.Thus, the C programmer can build their own library.
Post a Comment
0 Comments