ASCII Value of a Character in C

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

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

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

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

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

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.