Prev Next
- itoa() function in C language converts int data type to string data type. Syntax for itoa() function is given below.
char * itoa ( int value, char * str, int base );
- “stdlib.h” header file supports all the type casting functions in C language. But, it is a non standard function.
Example program for itoa() function in C:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int a=54325;
char buffer[20];
itoa(a,buffer,2); // here 2 means binary
printf("Binary value = %sn", buffer);
itoa(a,buffer,10); // here 10 means decimal
printf("Decimal value = %sn", buffer);
itoa(a,buffer,16); // here 16 means Hexadecimal
printf("Hexadecimal value = %sn", buffer);
return 0;
}
Output:
|
Binary value = 1101010000110101
Decimal value = 54325
Hexadecimal value = D435
|
……
Other inbuilt typecasting functions in C language:
- Typecasting functions in C language performs data type conversion from one type to another.
- Click on each function name below for description and example programs.
| S.no | Typecast function | Description |
| 1 | atof() | Converts string to float |
| 2 | atoi() | Converts string to int |
| 3 | atol() | Converts string to long |
| 4 | itoa() | Converts int to string |
| 5 | ltoa() | Converts long to string |
Prev Next
.