Utopper SkillUtopper Skill
  • Programming
    • Programming Examples
  • Interview Questions
    • DevOps Interview Questions
    • Android Interview Questions
  • How to
  • Tools
  • Top 10
  • Book Summaries
Reading: C Program To Print ASCII Value of a Character
Share
Utopper SkillUtopper Skill
Search
  • Book Summaries
  • Programming Examples
  • C Programming Example
  • Interview Question
  • How to
  • Top 10
Follow US
Utopper Skill > Programming Examples > C Programming Example > C Program To Print ASCII Value of a Character
Programming ExamplesC Programming Example

C Program To Print ASCII Value of a Character

Utopper Skill Team
By Utopper Skill Team Last updated: December 2, 2023
Share
6 Min Read
C Program To Print ASCII Value of a Character
SHARE
Table of Content
What is ASCII Value?Pseudo code to Print the ASCII Value of a CharacterApproach to Print the ASCII Value of a CharacterC Program to Print the ASCII Value of a Character
C Program To Print ASCII Value of a Character

The C++ program to print ASCII value of a character is a simple and fundamental program that is used to obtain the ASCII value of a character input by the user. ASCII stands for American Standard Code for Information Interchange, and it is a character encoding standard used in computing. In this program, the user inputs a character, and the program uses the int() function to convert the character to its corresponding ASCII value, which is then displayed to the console. This program is useful for beginners who want to learn about character encoding and working with characters in C++.

What is ASCII Value?

ASCII (American Standard Code for Information Interchange) character encoding assigns numeric codes to computer characters.

Each character has a 7-bit numeric code between 0 and 127 (total 128 characters). ASCII codes represent letters, numbers, punctuation marks, and control characters.

The ASCII code for uppercase “A” is 65, lowercase “a” is 97, and digit “0” is 48. ASCII codes allow text representation and manipulation across computer systems and programming languages.

Pseudo code to Print the ASCII Value of a Character

1. Input a character from the user.
2. Convert the character to its ASCII value.
3. Print the ASCII value.

And here’s the pseudocode in more detail:

1. Start
2. Declare a variable character of type character
3. Display "Enter a character: "
4. Read character from the user
5. Declare a variable asciiValue of type integer and initialize it to 0
6. Assign asciiValue the ASCII value of the character (cast character to integer)
7. Display "The ASCII value of <character> is <asciiValue>"
8. End

In this pseudocode, we first prompt the user to enter a character. Then, we declare a variable asciiValue to store the ASCII value of the character. By casting the character to an integer, we assign its ASCII value to asciiValue. Finally, we display the ASCII value to the user.

Approach to Print the ASCII Value of a Character

To print the ASCII value of a character in C programming, you can follow this approach:

  1. Declare a variable of type char to store the character.
  2. Read the character from the user.
  3. Use the %d format specifier with printf to print the ASCII value of the character.

Here’s the step-by-step approach in more detail:

  1. Start the program.
  2. Declare a variable character of type char.
  3. Display a message asking the user to enter a character.
  4. Read the character entered by the user and store it in the character variable.
  5. Use printf to display the ASCII value of the character. Format the output using %d to print the decimal representation of the ASCII value.
  6. End the program.

By following this approach, you can obtain the ASCII value of a character and display it to the user.

C Program to Print the ASCII Value of a Character

#include <stdio.h>
int main() {
    char character;

    printf("Enter a character: ");
    scanf("%c", &character);

    printf("The ASCII value of '%c' is %d.\n", character, character);

    return 0;
}

Output:

Enter a character: A
The ASCII value of 'A' is 65.

In this program, we declare a variable character of type char to store the input character. Then we prompt the user to enter a character using the printf function. The %c format specifier is used to read a character input from the user with the scanf function, and the & operator is used to get the address of the character variable.

After reading the character, we use printf to display the ASCII value of the character. The %d format specifier is used to print the decimal representation of the ASCII value.

In the given output example, the user enters the character ‘A’, and the program prints its ASCII value, which is 65.

Output:

Enter a character: x
The ASCII value of 'x' is 120.

In this program, we follow the same approach as before. The user is prompted to enter a character, and the program reads it using scanf. Then, using printf, we display the ASCII value of the character by using the %d format specifier.

In the given output example, the user enters the character ‘x’, and the program prints its ASCII value, which is 120.

  • Palindrome Number
  • Fibonacci Series in C
  • Prime Number in C
  • Even or Odd Number in C
TAGGED:ascii value programC Program Examples
Share This Article
Facebook Twitter Whatsapp Whatsapp Telegram Copy Link Print
Previous Article Even or odd program in c language C program to Find Even or Odd Number
Next Article Terraform Interview Questions and Answers 40 Best Terraform Interview Questions and Answers 2024
Most Popular
Learn C Programming (Basic to Advanced)
Array of Pointers in C
Utopper Skill Author By Utopper Skill Author
Java Interview Questions
Top 40+ Java Interview Questions and Answers (2024 Edition)
Utopper Skill Author By Utopper Skill Author
Learn C Programming (Basic to Advanced)
Passing Array to Function in C
Utopper Skill Author By Utopper Skill Author
Learn C Programming (Basic to Advanced)
C if Statement
Utopper Skill Author By Utopper Skill Author
Learn C Programming (Basic to Advanced)
Recursion in C
Utopper Skill Author By Utopper Skill Author

You Might Also Like

C++ Program To Print Prime Numbers From 1 To N
C Programming ExampleProgramming Examples

C++ Program To Print Prime Numbers From 1 To N

11 Min Read
C Program to Print Your Own Name
Programming ExamplesC Programming Example

C Program to Print Your Own Name with Example

2 Min Read
C Program To Convert Fahrenheit To Celsius
C Programming ExampleProgramming Examples

C Program To Convert Fahrenheit To Celsius

5 Min Read
C Program To Find LCM of Two Numbers
Programming ExamplesC Programming Example

C Program To Find LCM of Two Numbers

6 Min Read

Mail : [email protected]

Privacy Policy | DISCLAIMER | Contact Us

Learn

  • learn HTML
  • learn CSS
  • learn JavaScript

Examples

  • C Examples
  • C++ Examples
  • Java Examples

Study Material

  • Interview Questions
  • How to
  • Hosting
  • SEO
  • Blogging

 

© 2024 : UTOPPER.COM | Owned By : GROWTH EDUCATION SOLUTIONS PRIVATE LIMITED
Welcome Back!

Sign in to your account

Lost your password?