C Program to Find the ASCII Value of a Character

In C language, every character is represented by a numeric value according to its character encoding. The ASCII (American Standard Code for Information Interchange) standard assigns numeric values from 0 to 127 to characters, including letters, digits, symbols and control characters.

सी लैंग्वेज में प्रत्येक कैरेक्टर को उसके कैरेक्टर एन्कोडिंग के अनुसार एक संख्यात्मक मान दिया जाता है। ASCII (American Standard Code for Information Interchange) स्टैंडर्ड में अक्षरों, अंकों, विशेष चिह्नों और कंट्रोल कैरेक्टर्स के लिए 0 से 127 तक के संख्यात्मक मान निर्धारित किए गए हैं।

C Program

The following C program accepts a character from the user and displays its ASCII value.

निम्न C प्रोग्राम यूजर से एक कैरेक्टर इनपुट लेता है और उसकी ASCII वैल्यू प्रदर्शित करता है।

#include <stdio.h>
int main(void)
{
char ch;
printf("Enter a character: ");
if (scanf("%c", &ch) != 1)
{
printf("Invalid input!\n");
return 1;
}
printf("ASCII value of %c = %d\n", ch, (unsigned char)ch);
return 0;
}

Output

Example 1:

Enter a character: A
ASCII value of A = 65

Example 2:

Enter a character: a
ASCII value of a = 97

Example 3:

Enter a character: 5
ASCII value of 5 = 53

Explanation

  1. char ch; declares a character variable to store the input character.

    char ch; एक कैरेक्टर वेरिएबल घोषित करता है, जिसमें इनपुट कैरेक्टर स्टोर होता है।

  2. scanf("%c", &ch); reads one character entered by the user.

    scanf("%c", &ch); यूजर द्वारा दर्ज किया गया एक कैरेक्टर इनपुट लेता है।

  3. (unsigned char)ch converts the character to an unsigned character value before displaying it as an integer.

    (unsigned char)ch कैरेक्टर को unsigned character value में बदलता है, ताकि उसे integer के रूप में प्रदर्शित किया जा सके।

  4. printf() displays the character and its numeric value.

    printf() कैरेक्टर और उसकी संख्यात्मक वैल्यू प्रदर्शित करता है।

Important Points

  • ASCII value of uppercase A is from 65 to Z is 90.

  • ASCII value of lowercase a is from 97 to z is 122.

  • ASCII value of digit 0 is from 48 to 9 is 57.

  • ASCII value of space is 32.

  • ASCII वैल्यू A  65 से Z 90 तक होती है।

  • ASCII वैल्यू a 97 से z 122 तक होती है।

  • ASCII वैल्यू  अंक 0 की 48 से अंक 9 की 57 तक होती है।

  • Space की ASCII वैल्यू 32 होती है।

ASCII defines values from 0 to 127. On modern systems, the numeric value of a character outside the ASCII range depends on its character encoding.

ASCII में 0 से 127 तक के मान निर्धारित हैं। आधुनिक सिस्टम में ASCII रेंज से बाहर के कैरेक्टर की संख्यात्मक वैल्यू उसके character encoding पर निर्भर करती है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025