EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

ASCII Value in C

Home » Software Development » Software Development Tutorials » C Programming Tutorial » ASCII Value in C

ASCII Value in C

Introduction to ASCII Value in C

ASCII is abbreviated as the “American Standard Code for Information Interchange”. As we are humans we have our language to understand the same way machine also have the same thing to understand characters, digits, special characters that is ASCII representation of the character. It is a character encoding schema that is used for electronic communication.ASCII contains numbers, each character has its own number to represent. We have 256 character to represent in C (0 to 255) like character (a-z, A-Z), digits (0-9) and special character like !, @, # etc. This each ASCII code occupied with 7 bits in the memory. Let suppose ASCII value of character ‘C’ is 67. When we give input as ‘B’ machine treat it as 67 internally and stores its address. When we get back our original number compiler gives you 67 and other internal software converts these values into its equivalent characters.

ASCII values Table

ASCII value table

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

ASCII value table 2

How does ASCII Value Represent Internally in C?

1. Let take an example string as “ABCDEFG HIJK LMNO”.

2. When we pass this instruction to machine it will not store it as“ABCDEFG HIJK LMNO” but instead it will store its equivalent ASCII value.

3. Therefore now machine stored value is “65 66 67 68 69 70 71 32 72 73 74 75 32 76 77 78 79”.

4. ASCII value is 65, B is 66, C is 67, and so on. Space ASCII value is:

Syntax:

int p;
for(int p=0;p<255;p++)
{
Printf(“%c,%d”,p,p);//%c is for display character and %d is for ASCII value
}
 

Examples to Implement of ASCII Value in C

Below are the examples.

1. Capital A to Z ASCII Values.

Code:

//including basic C libraries
#include <stdio.h>
//main method for run C application
int main()
{
//declaration int variable
int capitalChars;
//iterating Capital ASCII values
for(capitalChars=65;capitalChars<91;capitalChars++)  // for loop from 65 to 90
{
//display ASCII values for its equivalent characters
printf("\n\tThe equivalent ASCII for  %c character is %d", capitalChars,capitalChars);
}
return 0;
}

Popular Course in this category
C Programming Training (3 Courses, 5 Project)3 Online Courses | 5 Hands-on Projects | 34+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,617 ratings)
Course Price

View Course

Related Courses
C++ Training (4 Courses, 5 Projects, 4 Quizzes)Java Training (40 Courses, 29 Projects, 4 Quizzes)

Output:

Output 1

2. Small A to Z ASCII Values

Code:

//including basic C libraries
#include <stdio.h>
//main method for run C application
int main()
{
//declaration int variable
int lowerChars;
//iterating lowe case characters ASCII values
for(lowerChars=97;lowerChars<123;lowerChars++)  // for loop from 97 to 122
{
//display ASCII values for its equivalent characters
printf("\n\tThe equivalent ASCII for lower case %c character is %d", lowerChars,lowerChars);
}
return 0;
}

Output:

Output 2

3. Space ASCII Value

Code:

//including basic C libraries
#include <stdio.h>
//main method for run C application
int main()
{
//declaration int variable
int space;
//iterating lowe case characters ASCII values
for(space=32;space<33;space++)  // for loop 32
{
//display ASCII values for its equivalent characters
printf("\n\tThe equivalent ASCII for space %c is %d", space,space);
}
return 0;
}

Output:

ASCII Value in C Example 3

4. Special Characters ASCII Values

Code:

//including basic C libraries
#include <stdio.h>
//main method for run C application
int main()
{
//declaration int variable
int specialChars;
//iterating lowe case characters ASCII values
for(specialChars=33;specialChars<48;specialChars++)  // for loop from 32 to 47
{
//display ASCII values for its equivalent characters
printf("\n\tThe equivalent ASCII for %c special character is %d", specialChars,specialChars);
}
for(specialChars=58;specialChars<65;specialChars++)  // for loop from 58 to 64
{
//display ASCII values for its equivalent characters
printf("\n\tThe equivalent ASCII for %c special character is %d", specialChars,specialChars);
}
for(specialChars=123;specialChars<127;specialChars++)  // for loop from 123 to 126
{
//display ASCII values for its equivalent characters
printf("\n\tThe equivalent ASCII for %c special character is %d", specialChars,specialChars);
}
return 0;
}

Output:

 Output 4

5. All ASCII Values in One Place

Code:

//including basic C libraries
#include <stdio.h>
//main method for run C application
int main()
{
//declaration int variable
int allChars;
//iterating lowe case characters ASCII values
for(allChars=0;allChars<256;allChars++)  // for loop from 0 to 255
{
//display ASCII values for its equivalent characters
printf("\n\tThe ASCII value of %c is %d", allChars,allChars);
}
return 0;
}

Output:

Example 5

6. Given Name ASCII Values

Code:

//including basic C libraries
#include <stdio.h>
//main method for run C application
int main()
{
// declaring char array variable
char charArray[20];
// declaring int variable
int var=0;
//Asking user to enter any name
printf("\n\tPlease enter you name to know your name ASCII values: ");
scanf("%s", charArray);
while(charArray[var]!='\0')  // iterating array characters sequentially
{
//display the your name character ASCII values
printf("\n\tThe ASCII value of character %c is %d", charArray[var],charArray[var]);
var++;
}
return 0;
}

Output:

Example 6

Conclusion

ASCII in C is used to represent numeric values for each character. This each character internally stored as ASCII value but not the same character we have given. We can display lower case, upper case alphabets, special characters etc. ASCII values by using their corresponding order. Present we have 255 ASCII characters are there in C.

Recommended Articles

This is a guide to ASCII Value in C. Here we discuss the Introduction to ASCII Value in C and its Table along with the different examples and code implementation. You can also go through our other suggested articles to learn more –

  1. Expression in C
  2. Volatile in C
  3. Inline Function in C
  4. Address Operator in C

C Programming Training (3 Courses, 5 Project)

3 Online Courses

5 Hands-on Projects

34+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
C Programming Tutorial
  • Function
    • Math Functions in C
    • Hashing Function in C
    • Recursive Function in C
    • Power Function in C
    • fputs in C
    • C puts() Function
    • fprintf() in C
    • fseek() in C
    • Stderr in C
    • ASCII Value in C
    • strcat() in C
    • Inline Function in C
    • sizeof() in C
    • Function Prototype in C
    • C ftell()
  • Basic
    • Introduction to C
    • What is C
    • Career in C Programming
    • Advantages of C
    • How to Install C
    • Best C Compilers
    • Data Types in C
    • Variables in C
    • C Keywords
    • C Command
    • Command Line Arguments in C
    • C Literals
    • Constants in C
    • Unsigned Int in C
    • String in C
  • Pointers
    • Pointers in C
    • Null pointer in C
    • Function Pointer in C
    • Double Pointer in C
    • Void Pointer in C
    • Const Pointer in C
    • Dangling Pointers in C
    • Pointer Arithmetic in C
  • Operators
    • C Operators
    • Arithmetic Operators in C
    • Relational Operators in C
    • Assignment Operators in C
    • Logical Operators in C
    • Conditional Operator in C
    • Modulus Operator in C
    • Ternary Operator in C
    • Address Operator in C
    • Unary Operator in C
    • Operators Precedence in C
    • Left Shift Operator in C
  • Control Statement
    • Control Statements in C
    • If Statement in C
    • If-else Statement in C
    • Else if Statement in C
    • Nested if Statement in C
    • #else in C
    • Structure Padding in C
    • Nested Structure in C
    • Continue Statement in C
    • Break Statement in C
    • Switch Statement in C
    • Goto Statement in C
  • Loops
    • Loops in C
    • For Loop in C
    • While Loop in C
    • Do While Loop in C
    • Nested Loop in C
    • Infinite Loop in C 
  • Array
    • Arrays in C Programming
    • 2-D Arrays in C
    • 3D Arrays in C
    • Multidimensional Array in C
    • Array Functions in C
    • Strings Array in C
  • Sorting
    • Sorting in C
    • Heap Sort in C
  • Advanced
    • Constructor in C
    • Encapsulation in C
    • C Storage Classes
    • Static Keyword in C
    • File Handling in C
    • Queue in C
    • Hexadecimal in C 
    • typedef in C
    • Memory Allocation in C
    • Linked List in C
    • Volatile in C
    • Tokens in C
    • Expression in C
    • Regular Expression in C
    • Error Handling in C
    • Types of Errors in C
    • Preprocessor in C
    • Preprocessor Directives in C
    • fscanf() in C
    • #Pragma in C
    • #ifndef in C
    • #undef in C
    • Macros in C
  • C programs
    • Patterns in C Programming
    • Star Patterns in C
    • Number Patterns in C
    • Swapping in C
    • Reverse Number in C
    • Palindrome in C Program
    • Factorial in C
    • Fibonacci Series in C
    • Square Root in C
    • Random Number Generator in C
    • Prime Numbers in C
    • Escape Sequence in C
    • Reverse String in C
    • Leap Year Program in C
    • Anagram Program in C
    • Strong Number in C
    • String Concatenation in C
    • C Programming Matrix Multiplication
    • Decimal to Octal in C
    • Expression Evaluation in C
    • Decimal to Hexadecimal in C
  • Interview question
    • C Programming Interview Questions

Related Courses

C Programming Training Course

C++ Training Course

Java Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - C Programming Training (3 Courses, 5 Project) Learn More