Posted By:
4 Jul, 2013 1:31 pm PDT

Predefined libraries in C++

What are predefined libraries? What are the different libraries and their functions which we commonly use?

Predefined libraries provide macros, type definitions and functions for tasks like string handling, mathematical computations, input/output processing and memory allocation.

Header files and their functions which we commonly use are:                                              

Function name  Description
strcpy(dest_string, src_string); copies one string to another
strcmp(string1, string2); compares two strings and returns 0, +ve or +ve values

returns the length of the string 

strcat(string1, string2); appends one string with another Function name Description 
abs(int n); returns the absolute value of n. (i.e |n|)
div(dividened, divisor); computes the quotient and remainder of integer division 
exp(int power) returns e^power 
strcat(string1, string2); Concatenates string1 and string2
log(int x); calculates log (base e) x
sqrt(int x); calculates the square root of x
pow(int x,int y); calculates x^y 
ceil(double x); returns nearest integer not less than x
floor(double x); returns nearest integer not greater than x


  • Macro Descriptioncin gets input from the user, cout displays output
  • Function Description: fopen opens a file fclose closes a file, fread reads from a file
  • fgets gets a character string from a file stream
  • fputs writes a character string to a file stream
  • getchar reads a character from stdin gets reads a character string
  • putchar writes a character to
  • stdout puts writes a character string
  • scanf reads formatted input from stdin,
  • a file stream or a buffer printf write formatted output to stdout,
  • a file stream or a buffer remove/erases a file,  rename renames a file Function


malloc(); allocates memory free();

deallocates preciously allocated memory

rand(); generates a random number

abort(); causes abnormal termination of the program

exit(); causes normal termination of the program


Function Description

time(); returns the current time of the system

clock(); returns raw processor clock time

Was it useful?  

Please login to reply to this problem.