Friday, May 15, 2020

learn function in c programming and header file

Function In C Programming is a reusable block of code that make a program simple and understandable a function can be modified or test without making any change in calling program. Function in programming language use to divided the code in number of subprograms which called as Function.


learn function in c programming and header file
learn function in c programming and header file


When you divided the program is Various subprograms, it becomes easy to manage every block of code or function easily. 


See positive end of function in programming : - 


If any error occur in any programming function then you can easily investigate faulty function and remove the error.

 You can easily call the function when you required which automatically save time and space of computer.


There Are Two Type Of Programming Function in C 

  • User Define Function In C
  • Library Function In C

 User Define Function In C programming Language : - 

As we all know a function is block of code that performs a specific task.

C Programming allows users to create an function according to their need and these function known as user define function in programming.

Library Function In C programming -

Instead of writing number of lines of code these function helps the programmer to save time by using already exist function in any programming language.  

Header File In C programming language

In order to access already function in C programming, certain header file need to be included before writing the body or any code.

List of header file in c programming language 

  • <stdio.h> (Standard input-output header)
This header file use to perform input and output operation like scanf() and printf().
  • <string.h> (String header)
use to perform all kind of operation related to string like strlen and strcpy.
  • <conio.h> (Console input-output header)
This header file Used to perform console input and console output operations like clrscr() to clear the screen and getch() to get the character from the keyboard.
  • <stdlib.h> (Standard library header)
This library header file used to perform standard function in c programming like malloc() and calloc() which are related to dynamic memory allocation.
  • <math.h> (Math header)
Use to perform mathematical operations like sqrt() and pow() and many more.
  • <ctype.h> (Character type header)
This header file helps to perform character type functions like isaplha() and isdigit() to find out about the given character is an alphabet or a digit.
  • <time.h> (Time header)
Use to perform function related to the date and time in c programming for example : - setdate() and getdate()
  • <assert.h> (Assertion header)
Use to perform function like assert( ) to get an integer type as a parameter.
  • <locale.h> (Localization header)
This header file Used to perform localization functions like setlocale() and localeconv() to set locale and get locale conventions.
  • <signal.h>(Signal header)
Used to perform signal handling functions like signal() and raise().
  • <setjmp.h> (Jump header)
Used in jump functions.
  • <stdarg.h> (Standard argument header)
Used to perform standard argument functions like va_start and va_arg().
  • <errno.h> (Error handling header)
Used to perform error handling operations like errno() to indicate errors in the program

Function in <stdio.h> header file 
this header file used almost in all kind of program written in c programming language.

  • printf() – Display output on the computer screen.
  • scanf() –  Take input from the user with the help of input device.
  • getchar() – Return characters on the computer screen.
  • putchar() – To display output as a single character on computer screen.
  • fgets() – Take a line as an input in C programming.
  • puts() –  Display a line as an output.
  • fopen() –  Open a file in C programming.
  • fclose() – Close a file in C programming.
Function in <Math.h> header file 

This header file is used in c programming when user wants to performs mathematical operations.

  • sqrt() – This function define in c to find the square root of a number
  • pow() – Function is used to find the power raised to that number.
  • fabs() – This function define in c to find the absolute value of a number.
  • log() – Find the logarithm of a number.
  • sin() – Find the sine value of a number.
  • cos() –  Define This function in c to find the cosine value of a number.
  • tan() – Define This function in c to find the tangent value of a number.
Example For Math.h in c programming 


#include 
#include 
int main()
{
printf("Welcome to DataFlair tutorials!\n\n");
double number=5, square_root;
int base = 6, power = 3, power_result;
int integer = -7, integer_result;
square_root = sqrt(number);
printf("The square root of %lf is: %lf\n", number, square_root);
power_result = pow(base,power);
printf("%d raised to the power %d is: %d\n", base, power, power_result);
integer_result = fabs(integer);
printf("The absolute value of %d is: %d\n", integer, integer_result);
return 0;
}

Function in <ctype.h> header file 

This header file is use character handling in  programming language. 

isalpha() –Check in c program if the character is an alphabet or not.
isdigit() – Check if the character is a digit or not in c program.
isalnum() – Used to check if the character is alphanumeric or not.
isupper() – Used to check if the character is in uppercase or not
islower() – Used to check if the character is in lowercase or not.
toupper() – Convert the character into uppercase.
tolower() – Convert the character into lowercase.
iscntrl() – Used to check if the character is a control character or not.
isgraph() – Used to check if the character is a graphic character or not.
isprint() – Check in c program if the character is a printable character or not
ispunct() – Check if the character is a punctuation mark or not.
isspace() – Used to check if the character is a white-space character or not.

isxdigit() – Used to check if the character is hexadecimal or not.


Summary 

This tutorial will help you to teach about all kind of used function in c programming language well this website design to explain library functions so we just focus on that. So here we discussed Header files and in build function in c programming language

Thank you for reading it.

0 comments:

Post a Comment