Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C++ (Built-in) Library Functions Complete List

Introduction to built-in Functions

The built-in functions are part of the C++ programming language. These are ready-made small program (or functions). The built-in functions are declared in different header files. C++ provides many built-in functions to solve various types of problems. The programmer uses built-in functions in writing program to perform various tasks. This saves the rogrammer’s time from writing his/her own functions. It is also reduce the source code of the program.
The built-in functions contains in a header file of programming language. Before using them in the program we have to declare header file that have these functions. For example, the "iostream" header file must be declared before using "clrscr()" function.

Functions Under "canio" Header File

The word “conic" stands for console input/output. The “conio” header file contains various basic input and output built-in functions. Some commonly used functions of this header file are as follows:
  1. clrser
  2. clreol
  3. getche
  4. kbhit
  5. gotoxy

What is clreol() Function

The word “clreol” is the short of clear end-of-line. The clreol() function is used to clear a line from the current cursor position up to the end of line. The other text printed on the screen is not cleared.
The declaration of clreol() function is as follows:
  void clreol (void);
The declaration of this function indicates that no parameter is passed to this function. This function returns no value.
The general syntax to call clreol() function is as follows:
clreol () ;

Example Program of clreol() Function


#include

main ()

{

   gotoxy (0, 9);

   clreol();

}

In this program, first statement (gotoxy) shifts the cursor at the first column of line number 10. The second statement clears this line up to the end-of-line.

What is getch() Function

The word “getch” stands for get character. The getch() function is used to get (input) a single character from keyboard during execution of the program. The entered character is not displayed on the screen. Similarly, the input process is automatically completed without pressing the Enter key. This function is normally used to pause the execution of program.
The declaration of getch() function is as follows:
int getch (void);
The declaration of this function indicates that no parameter is passed to this function. The output returned by this function is ‘int’ type. It returns the ASCII value of the input character. For example, if ‘A’ is entered, it returns ASCII value 65.
The general syntax to call getch() function is as follows:
  [var =] getch();
The ‘ver‘ is of ‘int‘ type. The ASCII value of entered character is stored into it. The ‘var‘ can also be of ‘char‘ type. In this case, the entered character is stored into it. The use of [var =] is optional.

Example Program of getch() Function

The following program written in C++ that inputs a word of 8-characters length using "getch". The entered characters are not seen on the screen during input process. The entered word should be displayed on the screen after the input process is completed.
#include
#include
using namespace std;
main ()
{
int i;
char password[10];
clrscr ();
cout for (i = 0; i password [ i ] = getch();
password [ i ] = '\0';
cout return 0;
}

What is kbhit() Function

The word “kbhit” stands for keyboard hit. The kbhit() function is used to check whether the user hit the keyboard or not during program execution. This function returns a non-zero (in the 1 form) value (true value) when any key on the keyboard is hit during the execution of the program. Otherwise, this function returns 0 (false value).
The declaration of kbhlt() function is as follows:
  int kbhit (void);

The declaration of kbhit() function 


indicates that no parameter is passed to this function. The output returned by this function is ‘int’ type. It returns non-zero value if keyboard is hit by the user, otherwise returns 0. The general syntax to call kbhit() function is as follows:
  [ var = ] kbhit();
Generally, The kbhit() function is used as test condition in loop statement to terminate a loop if any key on the keyboard is press. For example:-
while (!kbhit() )
{
    body of loop
}
To clear the concept of kbhit() function, read the given below example program.
The kbhit() Function Example Program
(A program that displays a message on the screen repeatedly until a key on the keyboard is hit.

#include
#include
main ()
{
int r = 1;
clrscr();
while ( !kbhit() )
{
cout gotoxy(25, r);
clreol();
r++;
if ( r== 24) r=1;
}
getch();
}

What is gotoxy() Function?

The gotoxy() function is used to move the cursor to the specified location in the current text window. This function is normally used when an output is to be displayed on a specified location on the screen. 
The declaration of the gotoxy() function is as follows:
void gotoxy (int, int);
The declaration of gotoxy() function indicates that two parameters both of "int" type are passed to this function. This output value returned by this function is nothing.
This general syntax to call gotoxy() function is given below:
gotoxy (x, y);
In the above syntax:
  • x: It indicates the x-coordinate or column number on the screen. Its value can be 0 to 79.
  • y: It indicates the y-coordinate or row number on the screen. Its value can be from 0 to 24 or 39.

      Following statements will display "welcome" on the screen at row 16 and starting from column 5:
gotoxy (4, 15);
cout

Functions Under "stdio" Header File

The word “stdio” stands for standard input/output. This header file contains various standard input and output functions. These functions are used to get input from the input device and to print/display the output on the output device. The most important and commonly used functions of 'stdio.h' header file are as follows:

  1. getchar
  2. putchar
  3. puts
  4. gets

What is getchar() Function? 

The word "getchar" is the short of get character. The getchar() function is similar to "getche" function of "canio.h" header file. It is also used to get a single character from a standard input device (i.e from keyboard) during program execution.
The main difference between getche() and getchar() function is that when getchar() function is used then we must have to pass Enter key to complete the input process.
The declaration of getchar() function is as follows:
int getchar (void);
Thet general syntax to call getchar() function is given below:-
[var =] getchar();
Note: The use of [var =] is optional. 

What is putchar() Function?

The word "putchar" stands for put character. The putchar() function is used to display a single character on the standard output device (such as computer screen).
The general syntax to call putchar() function is as follows:
putchar (char);
In the above syntax:
char: It represents the character to be displayed on the screen. It may be a character variable or character constant. In case of character constant, the character is enclosed in single quotation marks.

What is puts() Function?

The word "puts" is the short of put string. The puts() function is used to display string on the computer screen. The new line is automatically inserted after displaying the string.
The general syntax to call puts() function is as follows:
puts (string);
In the above syntax:
string: It represents the string to be displayed on the screen. It may be a string variable or string constant. In case of string constant, the string is enclosed in double quotation marks.
The following statement will display "welcome" on screen using puts() function:
puts ("welcome");
This statement is equivalent to:
cout

What is gets() Function?

The word "gets" stands for get string. The gets() function is used to input (or get) data into a string variable from the keyboard during program execution. Any type of characters, including spaces and special characters can be entered using this function. Enter key is pressed to complete the input process. When Enter key is pressed, a null character ('\0') is automatically added at the end of the string variable.
The general syntax to call gets() function is as follows:
gets (strvar);
In the above syntax:-
strvar: It represents the string variable into which data is to be saved.

Note: We can also input data into a string using "cin" stream object but space character can't be interested into the string using the "cin" stream object. When a space key is pressed during input process, the "cin" object immediately appends the null character ('\0') at that place in the string variable. Therefore, gets() function is specifically used to get data into string variable.

Functions Under "ctype" Header File

This header tile contains various built-in functions that are used to find out the types of different characters or values. It also contains functions used to convert lowercase letters to uppercase letters and vice versa. The most important and commonly used functions of this header file are as follows:
  1. isalpha
  2. isalnum
  3. isdigit
  4. isxdigit
  5. islower
  6. isupper
  7. isascii
  8. isspace
  9. isprint
  10. iscntrl 
  11. ispunct
  12. toascii
  13. tolower
  14. toupper

What is isalpha() Function

In C++, the isalpha() function is used to check whether a given character is alphabet latter or not. This function returns no-zero value (true value in the form of 1) if the given character "A" to "Z" or "a" to "z". Otherwise, this function returns 0 in the case of digits, special characters or any other data types.
The general syntax in C++ to call isalpha() function is as follows:
var = isalpha(c);
where:
cIt represents a single character or ASCII value for a character.
varIt indicates the integer variable into which the returned value is to be assigned. 

Example Program of isalpha() Function

#include 
#include
#include
int main ()
 {
   int i=0;
   char str[]= "C++" ;
   clrscr();
   while (str[i])
 {
   if (isalpha(str[i]))
 coutelse
 cout i++;
}
getch();
}

What is isalnum() Function

The isalnum() function is used to check whether the given character is alphanumeric character or not. This function returns a non-zero (true value) if the given character is alphabetic letters and numeric digits ( 'A' to 'Z' or 'a' to 'z' and '0' to '9' ). In the other case, this function returns 0.

Syntax of isalnum() Function

In C++, the general syntax to call isalnum() function is as follows:
var = isalnum(c); 
Where:
cIt indicates a single character or ASCII value for a character.
varIt indicates the integer variable into which the returned value is to be assigned.  
For example: 
If c = '5' then isalnum(c) will return 1 (non zero value).
If c = '&' then isalnum(c) will return 0.

What is isdigit() Function

The isdigit() function is used to check whether the given character is numeric digit or not. This function returns true value (non zero) if the given character is '0' to '9'. Otherwise, this function returns 0.

Syntax of isdigit() Function

In C++, the general syntax to call isdigit() function is as follows:
var = isdigit(c);

Where:
cIt indicates a single character or ASCII value for a character.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:
If c = '7' then isalnum(c) will return  1 (non zero value).


if c = 'a' then isalnum(c) will return 0.

What is isxdigit() Function

The isxdigit() function is used to check whether the given character is hexadecimal digit or not. This function returns true value (non zero) if the given character is '0' to '9', 'A' to 'F' or 'a' to 'f'. Otherwise, this function returns 0.


Syntax of isxdigit() Function

In C++, the general syntax to call isdigit() function is as follows:
var = isxdigit(c);

Where:
cIt indicates a single character or ASCII value for a character/digit.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:

  • If c = 'A' then isxdigit(c) will return  1 (non zero value). 
  • if c = 'Z' then isalnum(c) will return 0.


What is islower() Function

The islower() function is used to check whether the given character is a lowercase letter or not. This function returns non-zero value (true value) if the given character is 'a' to 'z'. Otherwise, this function returns 0.

Syntax of islower() Function

In C++, The general syntax to call islower() function is as follows:
var = islower(c);

Where:
cIt indicates a single character or ASCII value for a character.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:
If c = 'g' then islower(c) will return true value (1).


if c = 'G' then islower(c) will return 0.

What is tolower() Function

In C++, the tolower() function is used to convert the given uppercase letter (A to Z) to lowercase (a to z) letter.

Syntax of tolower() Function

The general syntax to call tolower() function is as follows:
var = tolower(c);

Where:
cIt indicates a single character that is to be converted into lowercase letter.
varIt indicates the variable into which the converted value is to be assigned.
For example:

  • If c = 'y' then tolower(c) will return letter "Y". 
  • if c = 'a' then tolower(c) will return letter "a".


What is isupper() Function

The isupper() function is quite opposite to the islower() function. This function is used to check whether the given character is a uppercase letter or not. This function returns non-zero value (true value) if the given character is 'A' to 'Z'. Otherwise, this function returns 0.

Syntax of isupper() Function

In C++, The general syntax to call islower() function is as follows:
var = isupper(c);

Where:
cIt indicates a single character or ASCII value for a character.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:

  • If c = 'H' then isupper(c) will return true value (1). 
  • if c = 'h' then isupper(c) will return 0.


What is toupper() Function

In C++, the toupper() function is used to convert the given lowercase letter (a to z) into uppercase (A to Z) letter. This function is opposite to the tolower() function.

Syntax of toupper() Function

The general syntax to call toupper() function is as follows:
var = toupper(c);

Where:
cIt indicates a single character that is to be converted into uppercase letter.
varIt indicates the variable into which the converted value is to be assigned.
For example:

  • If c = 'T' then toupper(c) will return letter "T". 
  • if c = 'p' then toupper(c) will return letter "P".


What is isascii() Function

The isascii() function is used to check whether the given value is ASCII value or not. This function returns a non-zero value (1) if the given value is '0' to '127'. Otherwise, this function returns 0 (false value).

Syntax of isascii() Function

In C++, the general syntax to call isascii() function is as follows:
var = isascii(c);

Where:
cIt represents ASCII value for a character.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:
If c = 127, then isascii(c) will return 1 (true value).


If c = 128, then isascii(c) will return 0.

What is toascii() Function

In C++, the toascii() function is used to convert a character to ASCII value.

Syntax of toascii() Function

The general syntax to call toascii() function is as follows:
var = toascii(c);

Where:
cIt indicates a single character whose ASCII value is to be found.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:

  • If c = 'A' then toascii(c) will return ASCII value 65. 
  • if c = 'a' then toascii(c) will return ASCII value 97.


What is isspace() Function

The isspace() Function is used to check whether the entered value (character) is a space or not. This function returns true (non-zero) value if the given character is space, tab, form feed, carriage return, new line and vertical tab etc. Otherwise, this function returns false (0).

Syntax of isspace() Function

In C++, the general syntax to call isspace() function is as follows:
var = isspace(c);

Where:
cIt indicates a single character or ASCII value for a character.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:

  • If c = '  ' then isspace(c) will return true value (1). 
  • if c = '/' then islower(c) will return 0.


What is isprint() Function

The isprint() function is used to check whether the given character is a printing character or not. All alphabets, digits, alphanumeric characters including space are printing characters. Space, new line, carriage return, tab, form feed and all other escape sequence characters are not printing characters.
The isprint() function returns true (1) if the given character is a printing character. Otherwise, this function returns false (0) in the case of space, new line, carriage return, tab, form feed and all other escape sequence characters.

Syntax of isprint() Function

The general syntax to call isprint() function is as follows:
var = isprint(c);

Where:
cIt indicates a single character or ASCII value for a character.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:
If c = 'e' then isprint(c) will return true value (1).


if c = '\n' then isprint(c) will return 0.

What is iscntrl() function

The iscntrl() function is used to check whether the given character is a control character or not. The new line ("\n"), carriage return ("\r"), form feed ("\f") etc. are control characters. It means that all escape sequence characters are control characters. This function returns true (1) if the given character is a control character. Otherwise, this function returns 0.

Syntax of iscntrl() Function

The general syntax to call iscntrl() function is as follows:
var = iscntrl(c);

Where:
cIt indicates a single control character.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:
If c = '\n' then isprint(c) will return true value (1).
if c = '$' then isprint(c) will return 0.

What is ispunct() Function

The ispunct() is used to check whether the given character is a punctuation character or not. The "{", "}", "," "[" , "]" etc. are punctuation characters. This function returns true value (1) if the given character is a punctuation character. Otherwise, this function returns 0.

Syntax of ispunct() Function

The general syntax to call ispunct() function is as follows:
var = ispunct(c);

Where:
cIt represents a punctuation character.
varIt indicates the integer variable into which the returned value is to be assigned.
For example:

  • If c = '[' then ispunct(c) will return true value (1). 
  • if c = '\n' then ispunct(c) will return 0.

Functions Under "math" Header File

This header file contains various mathematical functions. These functions are used to perform mathematical operations. The most important and commonly used functions of this header file are given below:
  1. cos
  2. sin
  3. tan
  4. abs
  5. fabs
  6. sqrt
  7. pow
  8. floor
  9. ceil
  10. fmod
  11. log
  12. log10

What is cos() Function?

The cos() function is used to find the trigonometric cosine of a given angle. The angle is given in radian as a real number. The declaration of cos() function is as follows:
double cos (double);
The declaration of cos() function indicates that a single parameter of "double" type is passed to this function. The output returned by cos() function is also of "double" type.
The general syntax to call the cos() function is as follows:
var = cos(x);
In the above syntax:
x: It indicates the angle in radian. It may be a variable, a constant or an expression.
y: It indicates the variable into which the returned value is to be assigned.


For example, if x = 0.0, then cos(x) will return 1.0

What is fmod() Function?

The word "fmod" is the short of "for floating-point modulus". The fmod() function is used to find the remainder by dividing two real numbers. The declaration of fmod() function is as follows:
double  fmod (double, double);
The declaration of fmod() function indicates that two parameters both of "double" type are passed to this function. The output returned by fmod() function is also of "double" type.
The general syntax to call fmod() function is as follows:
var = fmod (x, y);
In the above syntax:
x: It indicates the numerator. It may be a variable, constant value or expression.
y:It indicates the denominator. It may be a variable, constant value or expression.
var: It indicates the variable of "double" type into which the returned value is to be assigned.
For exampleif x = 9.5 and y = 4.0 then fmod(x, y) will return 1.5.

What is pow() Function?

The pow() function is used to calculate the exponential power of a given number. The declaration of pow() function is as follows:
double pow (double, double);
The declaration of pow() function indicates that two parameters both of "double" types are passed to this function. The output returned by this function is also of "double" type.
The general syntax to call this function is as follows:
var = pow (x, y);
In the above syntax:
x: It indicates a value whose exponential power is to be calculated. It may be a variable, constant value or expression.
y: It indicates a value to be used as exponential power.
var: It indicates the variable of "double" type into which the returned vale is to be stored.
The following statement will calculate 2^3 and display the result on the screen.
cout

What is floor() Function?

The floor() function is used to round a float or double type value. It returns the integeral part of the float or double value that is not greater than the given value. It is less than or equal to the given value.
The declaration of floor() function is as follows:
double floor (double);
The declaration of this function indicates that a single parameter of "double" type is passed to this function. The output returned by this function is also of "double" type.
The general syntax to call this function is as follows:
var = floor (x);
In the above syntax:-
x: It indicates a float or double type value (such as real number) that is to be rounded. It may be a constant, a variable or expression.
var:It indicates the variable into which the returned value is to be stored.
For example:-
If x = 623.456, then floor(x) will return 623.0
If x = -99.2, then floor(x) will return -100.0

What is ceil() Function?

The ceil() function is similar to floor() function. The ceil() function is also used to round a float or double type value. It returns the integral part of the float or double value that is greater than the given value.
The declaration of ceil() function is as follows:
double ceil (double);
The declaration of this function indicates that a single parameter of "double" type is passed to this function. The output returned by ceil() function is also of "double" type.
The general syntax to call ceil() function is given below:-
var = ceil (x);
In the above syntax:
x: It indicates a real number (double or float) that is to be rounded. It may be a expression, a constant or variable.
var: It indicates the variable into which the returned value is to be assigned.
For example:-
If x = 623.256, then ceil (x) returns 624.0
If x = -19.3, then ceil (x) returns -19.0

What is fabs() Function?

The fabs() function is used to find the absolute value of a real number or floating pointing number. The declaration of fabs() function is as follows:
long double fabs (long double);
The declaration of fabs() function indicates that a parameter of "long double" type is passed to this function. The output returned by this function is also of "long double" type.
The general syntax to call this function is as follows:
var = fabs (x);
In the above syntax:-
x: It indicates a variable, constant value or expression of type long double whose absolute value is to be found. For example, if value of x is -150.7 then this function will return 150.7.
var: It indicates the variable of "long double" type which the returned absolute value is to be assigned.

What is abs() Function?

The abs() function is used to find the absolute value of an integer value. The absolute value is a having no sign. The declaration of abs() function is as follows:
int abs (int);
The declaration of abs() function indicates that an integer parameter is passed to this function. The The general syntax to call this function is given below:-
var = abs (x);
In the above syntax:
x: It indicates an integer variable, integer constant value or expression whose absolute value is to be found. For example, if value of x is -44, then this function will return 44.
var: It indicates the variable of "int" type into which the returned absolute value is to be assigned.

What is sqrt() Function?

The sqrt() function is used to calculate the square root of a positive number. The declaration of sqrt() function is as follows:
double sqrt (double);
The declaration of sqrt() function indicates that a parameter of "double" type is passed to this function. The output returned by this function is also of "double" type.
The general syntax to call this function is given below:
var = sqrt(n);
In the above syntax:-
n: It indicates a variable, constant value or expression of type double whose square root is to be found. For example, if value of 'n' is 25.0 then this function will return 5.0.
var: It indicates the variable of "double" type into which the returned value is to be stored.

Functions Under "string" Header File

This header file contains the string related built-in functions. These functions are used to process strings. The most important and commonly used string functions of this header file are described as under:
  1. strlen 
  2. memcmp 
  3. memicmp 
  4. strcmp 
  5. stnicmp 
  6. strncmp 
  7. strnicmp 
  8. strspn 
  9. strcspn 
  10. strcoll 
  11. strstr 
  12. memchr 
  13. strchr 
  14. strrchr  
  15. strpbrk  
  16. strrev 
  17. memset 
  18. strset  
  19. strnset 
  20. strlwr 
  21. strupr 
  22. memcpy 
  23. memmove 
  24. strcpy 
  25. strncpy  
  26. strdup 
  27. strcat 
  28. strncat  
  29. strtok 

What is strlen() Function

The word "strlen" is the short of string length. The strlen() function is used to find out the length of a string. This function counts the total number of characters in the string including spaces. But, the null character ('\0') is not counted.
In C++, the general syntax of strlen() function is as follows:
var = strlen (string);



Where:
stringIt represents the given string whose length is to be found. It may be a string variable or constant.
varIt indicates the integer variable into which the length of the string is to be stored.

Example of strlen() Function

The following source code of the C++ program inputs a string variable and finds its length using strlen() function.
#include
#include
#include
main()
 {
   char str[200];
   cout   gets(str);
   cout   return 0;
 }
Output:
Enter a string: C++ Tutorials
Length of string is: 13

What is memcmp() Function

The word "memcmp" is the short of memory compare. In C++, the memcmp() function is used to compare specified number of bytes of two strings stored in two blocks of memory. Two strings are compared by "byte-by-byte" in this function. The comparison is case sensitive, it means that this function keep difference between lowercase and uppercase letters of the string.
The general syntax of this function is:
var = memcmp (ptr1, ptr2, num);

Where:

varIt represents integer variable that is used to store output returned by function. 
ptr1It indicates pointer to first block of memory.
ptr2It indicates pointer to second block of memory.
numIt represents number of bytes to compare.
The memcmp() function returns output in the following ways:
  • If first string is equal to the second string, then it will return 0.
  • If first string is less than second string, then it will return less than 0.
  • If first string is greater than second string, then it will return greater than 0.

Example of memcmp() Function

The following source code of C++ program compare two strings.
#include
#include
using namespace std;
main()
 {
   char *str1 = "abcd";
   char *str2 = "abcd";
   char *str3 = "wxyz";
   int num;
   num = memcmp (str1, str2, 3);
   if (num == 0)
          cout   num = memcmp (str2, str3, 3);
   if (num > 0)
          cout   else
          coutreturn 0;
}

What is memicmp() Funaction

The word "memicmp" is stands for memory ignore compare. This function is similar to memcmp() function but here the comparison is not case sensitive. Its mean that memicmp() function ignores the character case (lower or upper). It is also used to compare specified number of bytes (or characters) of two strings stored in two memory blocks.
In C++, the general syntax of this function is as follows:
var = memcmp (ptr1, ptr2, num);

Where:
varIt represents integer variable that is used to store output returned by function. 
ptr1It indicates pointer to first block of memory.
ptr2It indicates pointer to second block of memory.
numIt represents number of bytes to compare.
The memicmp() function returns output in the following ways:
  • If first string is equal to the second string, then it will return 0.
  • If first string is less than second string, then it will return less than 0.
  • If first string is greater than second string, then it will return greater than 0.

Example of memicmp() Function

The following source code of C++ program compare two strings.
#include
#include
using namespace std;
main()
 {
   char *s1 = "abcd";
   char *s2 = "ABCD";
   char *s3 = "wxyz";
   int num;
   num = memcmp (s1, s2, 3);
   if (num == 0)
          cout   num = memcmp (s2, s3, 3);
   if (num > 0)
          cout   else
          coutreturn 0;
}
The memcmp() and memicmp() both functions are similar, the main difference is that memcmp() function is case sensitive (keep difference between lower and upper case letters). Whereas the memicmp() function doesn't keep difference between lower and upper case letters.

Functions Under "graphics" Header File

In C++, we can create different objects such as lines, circles, rectangle and many other shapes using various graphics built-in functions. The commonly used graphics functions used to create graphics objects are as follows:
  1. circle 
  2. arc 
  3. pieslice 
  4. putpixel 
  5. getpixel 
  6. line
  7. rectangle
  8. setlinestyle 
  9. bar 
  10. har3d 
  11. getimage 
  12. putimage 
    In graphics mode, text can also be displayed in different fonts, styles, sizes, colors and directions. The graphics functions that are commonly used to create and print text are as follows:

    1. outtext
    2. moveto
    3. Tlie outtextxy
    4. settextstyle 
    5. setcolor
    6. setbkcolor 

    What is arc() Function? 

    The arc() function is used to draw a circular arc starting from a specified angle and up to another special specified angle, along the fixed centered point (x,y) with specified radius. The general syntax of arc() function is as follows:
    arc (x,y, stangle, endangle, radius);
    All the five parameters are of int type. These may be constants or variables.
    In the above syntax:

    1. x & y: It represents the center point of the arc. These are the x-coordinate and y-coordinate of the center of the arc on the screen.
    2. stangle: It represents the starting angle of the arc in degree.
    3. endangle: It represents the ending angle of the arc in degree.
    4. radius: It represents the radius of the arc.


    Note: The arc() function can also be used to draw a circle by giving the starting angle 0 (zero) and ending angle 360 degree. Similarly, it can also be used to draw line by giving the same values for starting and ending angles. 

    Example of arc() Function

    The following program code draws arcs with different radius, colors, starting angles & ending angles and having the same center point.
    #include
    #include
    main()
    {
          int d, m, r, co;
          d = DETECT;      //Auto-detect
          initgraph (&d, &m, " ");
          cleardevice();
          for (co = 1; co       {
             setcolor (co);
             arc (300, 200, 45, 145, co*10);
           }
    cleardevice();
    }

    Example 2: The following program draws circle with different radii & colors and having the same center point by using arc function.

    #include
    #include
    main()
    {
          int d, m, r, co;
          d = DETECT;      //Auto-detect
          initgraph (&d, &m, " ");
          cleardevice();
          for (co = 1; co       {
             setcolor (co);
             arc (300, 200, 0, 360, co*10);
           }
    getch();
    closegraph();
    }



    This post first appeared on Programming Explain, please read the originial post: here

    Share the post

    C++ (Built-in) Library Functions Complete List

    ×

    Subscribe to Programming Explain

    Get updates delivered right to your inbox!

    Thank you for your subscription

    ×