C – ltoa() function

       Prev                                                                                              Next

  • ltoa() function in C language converts long data type to string data type. Syntax for ltoa() function is given below.

char *ltoa(long N, char *str, int base);

  • “stdlib.h” header file supports all the type casting functions in C language.


Example program for ltoa() function in C:

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

int main()
    long  a=10000000;
    char buffer[50];
    ltoa(a,buffer,2);   // here 2 means binary
    printf("Binary value = %sn", buffer);

    ltoa(a,buffer,10);   // here 10 means decimal
    printf("Decimal value = %sn", buffer);

    ltoa(a,buffer,16);   // here 16 means Hexadecimal
    printf("Hexadecimal value = %sn", buffer);
    return 0;


Binary value = 100110001001011010000000
Decimal value = 10000000
Hexadecimal value = 989680

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

Continue on C – Miscellaneous functions….

       Prev                                                                                              Next