ASCII Value of a Character in C

Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Overview
Every character has an ASCII value associated with it. Characters are stored in the memory using their ASCII values in C. If we wish to know the ASCII value of any given character, we can write a program to find out the ASCII values in C.
Prerequisites
C Program To Print ASCII Value of a Character
To display the ASCII values in C of any character variable, we use the %d format specifier in the printf() statement. Let us take a look at how it works.
Input:
Output:
In the above example, we printed the ASCII value in C of the letter "z" by using %d format specifier in the printf() statement. The %d specifier returns an integer value. So, when we use it in a printf() statement, the character variable automatically gets converted to its corresponding ASCII value.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Complexity Analysis
-
Time Complexity : O(1)
- The time complexity of this program is constant. Regardless of the input character, the program's execution time remains the same. It directly prints the ASCII value using the %d format specifier, which is an efficient operation with a constant time overhead.
-
Auxiliary Space Complexity : O(1)
- The program's space complexity is also constant. It utilizes a minimal amount of additional memory for storing variables and the input character. The space required does not depend on the size of the input or any other factors, making it O(1).
This program's efficiency in terms of time and space complexity makes it a suitable choice for quickly obtaining the ASCII value of a character without any significant resource overhead.
Conclusion
- ASCII stands for American Standard Code for Information Interchange.
- There are 256 ASCII encoded characters but we use only 128 characters (0 to 127).
- We can print the ASCII values in C of any character by using the %d format specifier.
- To print all ASCII characters, we can use a loop that iterates through numbers 0 to 255 and then print the characters using %c and %d format specifiers.




