DEV Community

Cover image for How to convert Character into integer and vice-versa?
stalin s
stalin s

Posted on

How to convert Character into integer and vice-versa?

ASCII code link: https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
//convert an integer into a character

int p = 54;
char x = (char)p;

//Convert character into an integer

char p ='a';
int x = (int) p;

include

using namespace std;

int main()
{
// integer to character conversion
int p = 43;
char x ;
x = (char)p;
cout<<x<<endl;
}

//the output of the following code would be '+'

include

using namespace std;

int main()
{
// integer to character conversion
char x = 56;
int p ;
p = (int)x;
cout<<p<<endl;
}

//the output of the following code would be 56

Top comments (0)