How to convert int to char in c programming?

How to convert int to char in c?

We can convert an integer to character by adding ‘0’ (zero) character.

char datatype is represented as ascii values in c programming. Ascii values are integer values if we add the ‘0’ then we get the ascii of that integer digit that can be assigned to a char variable. Then if we access that char using %c we can print it.

If we want to convert a number then we have to extract the digit and then we have to convert it to char array.

Have a look at the below example for converting an int to character value.


int main()
 int a=1;
 char c=a+'0';
 printf("Converted character is %c",c);


	Converted character is 1

People also read