The Wayback Machine - https://web.archive.org/web/20240621033619/https://www.geeksforgeeks.org/c-ascii-value/
Open In App

ASCII Value of a Character in C

Last Updated : 08 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

American Standard Code for Information Interchange (ASCII) is a character encoding standard that assigns a unique numerical value to all characters including special symbols. In C programming, the ASCII value of the character is stored instead of the character itself. For example, the ASCII value of ‘A’ is 65.

  • Each character or special character is represented by some ASCII code.
  • Each ASCII code occupies 7 bits in memory.
  • Each character variable is assigned an ASCII value ranging from 0 to 127.

In this article, we will learn how to find and print the ASCII value of the character in C.

C Program To Print ASCII Value of a Character

We use a format specifier here to give the numeric value of the character. Here %d is used to convert a character to its ASCII value.

C




// C program to print
// ASCII Value of Character
#include <stdio.h>
 
// Driver code
int main()
{
    char c = 'k';
 
    // %d displays the integer value of
    // a character
    // %c displays the actual character
    printf("The ASCII value of %c is %d", c, c);
    return 0;
}


Output

The ASCII value of k is 107

Complexity Analysis

  • Time complexity: O(1)
  • Auxiliary Space: O(1)

Refer to the complete article Program to print ASCII Value of a character for more methods to print the ASCII value of a character.


Previous Article
Next Article

Similar Reads

Replace every character of string by character whose ASCII value is K times more than it
Given string str consisting of lowercase letters only and an integer k, the task is to replace every character of the given string with a character whose ASCII value is k times more than it. If the ASCII value exceeds 'z', then start checking from 'a in a cyclic manner. Examples: Input: str = "abc", k = 2 Output: cde Explanation: a is moved by 2 ti
9 min read
Check if a string contains a non-ASCII value in Julia - ascii() Method
The ascii() is an inbuilt function in Julia which is used to convert a specified string to a String type and also check the presence of ASCII data. If the non-ASCII byte is present, throw an ArgumentError indicating the position of the first non-ASCII byte. Syntax: ascii(s::AbstractString) Parameters:s::AbstractString: Specified stringReturns: It r
1 min read
Convert Character value to ASCII value in R Programming - charToRaw() Function
charToRaw() function in R Language is used to convert the given character to their corresponding ASCII value or "raw" objects. Syntax: charToRaw(x)Parameters: x: Given characters to be converted Example 1: C/C++ Code # R program to illustrate # charToRaw function # Calling charToRaw() function over # some alphabets x &lt;- charToRaw(&quot;a&quot;)
1 min read
What is ASCII - A Complete Guide to Generating ASCII Code
The American Standard Code for Information Interchange, or ASCII, is a character encoding standard that has been a foundational element in computing for decades. It plays a crucial role in representing text and control characters in digital form. Historical BackgroundASCII has a rich history, dating back to its development in the early 1960s. Origi
13 min read
Substring with maximum ASCII sum when some ASCII values are redefined
Given a string W, and two arrays X[] and B[] of size N each where the ASCII value of character X[i] is redefined to B[i]. Find the substring with the maximum sum of the ASCII (American Standard Code for Information Interchange) value of the characters. Note: Uppercase &amp; lowercase both will be present in the string W. Input: W = "abcde", N = 1,
9 min read
ASCII NULL, ASCII 0 ('0') and Numeric literal 0
The ASCII (American Standard Code for Information Interchange) NULL and zero are represented as 0x00 and 0x30 respectively. An ASCII NULL character serves as a sentinel character of strings in C/C++. When the programmer uses '0' in his code, it will be represented as 0x30 in hex form. What will be filled in the binary integer representation in the
3 min read
Total character pairs from two strings, with equal number of set bits in their ascii value
Given two strings s1 and s2. The task is to take one character from the first string and one character from the second string and check if the ASCII values of both characters have the same number of set bits. Print the total number of such pairs. Examples: Input: s1 = "xcd", s2 = "swa" Output: 1 Only valid pair is (d, a) with ASCII values as 100 an
6 min read
Program to print ASCII Value of a character
Given a character, we need to print its ASCII value in C/C++/Java/Python. Examples : Input : a Output : 97 Input : DOutput : 68 Here are few methods in different programming languages to print ASCII value of a given character :  Python code using ord function : ord() : It converts the given string of length one, returns an integer representing the
4 min read
C++ Program To Print ASCII Value of a Character
Given a character, we need to print its ASCII value in C++.  Examples: Input: a Output: 97 Input: DOutput: 68 Using Type ConversionHere int() is used to convert a character to its ASCII value. Below is the C++ program to implement the above approach:  [GFGTABS] C++ // C++ program to print // ASCII Value of Character #include &lt;iostream&gt; using
2 min read
Convert Hexadecimal value String to ASCII value String
Given the Hexadecimal value string as input, the task is to convert the given hexadecimal value string into its corresponding ASCII format string. Examples:  Input: 6765656b73Output: geeks Input: 6176656e67657273Output: avengers The “Hexadecimal” or simply “Hex” numbering system uses the Base of 16 system. Being a Base-16 system, there are 16 possi
6 min read