Header files “stdio.h” and “stdlib.h” in C


stdio.h

The header file stdio.h stands for Standard Input Output. It has the information related to input/output functions.

Here is the table that displays some of the functions in stdio.h in C language,

Sr.No.Functions & Description
1printf()
It is used to print the strings, integer, character etc on the output screen.
2scanf()
It reads the character, string, integer etc from the keyboard.
3getc()
It reads the character from the file.
4putc()
It writes the character to the file.
5fopen()
It opens the file and all file handling functions are defined in stdio.h header file.
6fclose()
It closes the opened file.
7remove()
It deletes the file.
8fflush()
It flushes the file.

Here is an example of stdio.h in C language,

Example

 Live Demo

#include<stdio.h>

int main () {
   char val;

   printf("Enter the character: \n");
   val = getc(stdin);
   printf("Character entered: ");
   putc(val, stdout);

   return(0);
}

Output

Here is the output

Enter the character: s
Character entered: s

stdlib.h

The header file stdlib.h stands for Standard Library. It has the information of memory allocation/freeing functions.

Here is the table that displays some of the functions in stdlib.h in C language,

Sr.No.Functions & Description
1malloc()
It allocates the memory during execution of program.
2free()
It frees the allocated memory.
3abort()
It terminates the C program.
4exit()
It terminates the program and does not return any value.
5atol()
It converts a string to long int.
6atoll()
It converts a string to long long int.
7atof()
It converts a string to floating point value.
8rand()
It returns a random integer value

Here is an example of stdlib.h in C language,

Example

 Live Demo

#include <stdio.h>
#include<stdlib.h>

int main() {
   char str1[20] = "53875";
   char str2[20] = "367587938";
   char str3[20] = "53875.8843";

   long int a = atol(str1);
   printf("String to long int : %d\n", a);

   long long int b = atoll(str2);
   printf("String to long long int : %d\n", b);

   double c = atof(str3);
   printf("String to long int : %f\n", c);
   printf("The first random value : %d\n", rand());
   printf("The second random value : %d", rand());

   return 0;
}

Output

Here is the output

String to long int : 53875
String to long long int : 367587938
String to long int : 53875.884300
The first random value : 1804289383
The second random value : 846930886

Updated on: 25-Jun-2020

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements