C Program to Find ASCII Value of a Character

devquora
devquora

Posted On: Jan 27, 2023

C Program to Find ASCII Value of a Character

 

Overview:

In This Article you will find and print the ASCII value of characters such as letters, numbers, and other special characters. First of all let's understand about character in C Programming. Then, I will discuss the ASCII value of a character. Moreover, I will Demonstrate ASCII Value of some Characters. After all, I will write the logic and C Program to Find the ASCII Value of a Character with output.

Table of contents:

  1. What do you mean by characters in C Programming?
  2. C character set
  3. What is ASCII value of characters?
  4. Demonstration for ASCII Value of some Characters
  5. Logic to Find ASCII Value of a Character
  6. C Program to Find ASCII Value of a Character
  7. Conclusion

What do you mean by characters in C Programming?

Character denotes any alphabet, digit or special symbol used to represent information. Characters are separately kept inside single quotes. For instance, Character a is represented as 'a'. Character # is represented as '#'.

C character set

The character set is the fundamental raw material of any language and they are used to represent information. Like natural languages, computer language will also have a well defined character set, which is useful to build the programs. The characters in C are grouped into the following two categories:

1. Source character set

    a.      Alphabets
    b.      Digits
    c.      Special Characters
    d.      White Spaces

2. Execution character set

    a.     Escape Sequence

1. Source character set:-

ALPHABETS:

Uppercase letters:

A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

Lowercase letters:

a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z

DIGITS:

       0, 1, 2, 3, 4, 5, 6, 7, 8, 9

SPECIAL CHARACTERS:

 ~ tilde                            
 % percent sign               
 | vertical bar         
 @ at the rate symbol               
 + plus sign                    
 < less than
 _ underscore                
 - minus sign                 
 > greater than       
 ^ caret                        
 # hash sign              
 = equal to
 & ampersand                 
 $ dollar sign                 
 / slash                  
 ( left parenthesis      
 * asterisk                      
 \ back slash
 ) right parenthesis       
 ′ apostrophe                
 : colon                  
 [ left bracket               
 " quotation mark         
 ; semicolon
 ] right bracket              
 ! exclamation mark     
 , comma                
 { left curly brace               
 ? Question mark       
 . dot operator           
 } right curly brace    

WHITESPACE CHARACTERS:

\b   blank space               
\t   horizontal tab                       
\v   vertical tab             
\r   carriage return          
\f   form feed                   
\n   new line  
\\   Back slash                 
\’   Single quote                          
\"   Double quote       
\?   Question mark          
\0   Null                            
\a   Alarm (bell)

2. Execution Character Set:

Certain ASCII characters are unprintable, which means they are not displayed on the screen or printer. Those characters perform other functions aside from displaying text. Examples are backspacing, moving to a newline, or ringing a bell.

They are used in output statements. Escape sequence usually consists of a backslash and a letter or a combination of digits. An escape sequence is considered as a single character but a valid character constant.

These are employed at the time of execution of the program. Execution characters are always represented by a backslash (\) followed by a character. Note that each one of character constants represents one character, although they consist of two characters. These character combinations are called a escape sequence.

What is ASCII value of a character?

A character variable holds ASCII value (an integer number between 0 and 127) rather than that character itself in C programming. That value is known as the ASCII value. For example, the ASCII value of 'A' is 65.  Each character or number has its own ASCII value.

Demonstration for ASCII Value of some Characters

ASCII Value

Logic to Find ASCII Value of a Character

  • Step 1: Define a character variable.
  • Step 2: Ask the user to insert any character with format specifier %c.
  • Step 4: The character will be assigned to the variable ‘a’
  • Step 5: print the character variable with format specifier %d to find out the ASCII value of the character

C Program to Find ASCII Value of a Character

/* C Program to identify ASCII Value of a Character */
#include <stdio.h>
#include <conio.h>
int main()
{
  char a;
  
  printf("Kindly insert any character = ");
  scanf("%c",&a);
  
  printf("\nThe ASCII value of inserted character = %d",a);
  return 0;
}

The output of the Program with code:

When the above code is executed, It produces the following results:

Kindly insert any character = a The ASCII value of inserted character = 97

ASCII Value Output

Explanation:

In above Program, ask to the user to Kindly insert any character = when user insert 'A' as input then it displays the output as The ASCII value of inserted character = 65

Conclusion:

This program evaluates The ASCII value of inserted character. In this program, the user is asked to enter a character If userenter 'A'. Then, this character is stored in variable a. When %d format string is used, 65  is displayed as the ASCII value of A. When %c format string is used, 'A' itself is displayed.

    Please Login or Register to leave a response.

    Related Articles

    C Program Examples

    C Program to convert Decimal to Binary Number

    A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

    C Program Examples

    C program to reverse a string

    This program reversed the entered string that means opposite of the previous string sequence...

    C Program Examples

    C program to reverse an Integer number

    Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..