Home » C solved programs » C basic programs

C - Print ASCII value of entered character

In this C program, we will read a character values in a character variable and then store its ASCII value to an integer variable.

It’s really very easy to convert a character value to an integer variable, consider the given statement,

 integer_variable = (int)character_variable;

Print ASCII value of entered character in C

/*C - Print ASCII value of entered character.*/
 
#include <stdio.h>
 
int main(){
    char ch;
    int asciiValue;
 
    printf("Enter any character: ");
    scanf("%c",&ch);
 
    asciiValue=(int)ch;
 
    printf("ASCII value of character: %c is: %d\n",ch,asciiValue);
 
}

Output

    Enter any character: x
    ASCII value of character: x is: 120






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.