{"id":4331,"date":"2026-11-22T06:12:18","date_gmt":"2026-11-22T06:12:18","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=4331"},"modified":"2026-11-22T06:12:44","modified_gmt":"2026-11-22T06:12:44","slug":"how-to-find-ascii-value-in-c","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/how-to-find-ascii-value-in-c\/","title":{"rendered":"How to Find ASCII Value in C (5 Programs with Output)"},"content":{"rendered":"<p>Every character in C is stored as a small integer. For ordinary English letters, digits and symbols, that integer is the character&#8217;s <strong>ASCII value<\/strong>. So finding the ASCII value in C is easy: read the character into a <code>char<\/code> variable and print it with <code>%d<\/code> instead of <code>%c<\/code>.<\/p>\n<h2>What Is ASCII?<\/h2>\n<p>ASCII stands for <strong>American Standard Code for Information Interchange<\/strong>. It gives a number from 0 to 127 to 128 characters: English letters, digits, punctuation, the space, and some control characters such as newline.<\/p>\n<table>\n<thead>\n<tr>\n<th>Character<\/th>\n<th>ASCII value<\/th>\n<th>Character<\/th>\n<th>ASCII value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Space<\/td>\n<td>32<\/td>\n<td><code>A<\/code><\/td>\n<td>65<\/td>\n<\/tr>\n<tr>\n<td><code>!<\/code><\/td>\n<td>33<\/td>\n<td><code>Z<\/code><\/td>\n<td>90<\/td>\n<\/tr>\n<tr>\n<td><code>&amp;<\/code><\/td>\n<td>38<\/td>\n<td><code>a<\/code><\/td>\n<td>97<\/td>\n<\/tr>\n<tr>\n<td><code>0<\/code><\/td>\n<td>48<\/td>\n<td><code>z<\/code><\/td>\n<td>122<\/td>\n<\/tr>\n<tr>\n<td><code>9<\/code><\/td>\n<td>57<\/td>\n<td>Newline (<code>n<\/code>)<\/td>\n<td>10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Two patterns are worth remembering: capital letters run from 65 to 90, and small letters from 97 to 122. Each small letter is exactly <strong>32 more<\/strong> than its capital.<\/p>\n<h2>Program 1: Find the ASCII Value of a Character<\/h2>\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nint main(void) {\n    char ch;\n\n    printf(\"Enter a character: \");\n    scanf(\" %c\", &amp;ch);\n\n    printf(\"The ASCII value of %c is %dn\", ch, ch);\n    return 0;\n}<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>Enter a character: &amp;\nThe ASCII value of &amp; is 38<\/code><\/pre>\n<h3>How it works<\/h3>\n<ol>\n<li><code>scanf(\" %c\", &amp;ch)<\/code> reads one character. The space before <code>%c<\/code> skips any leftover spaces or newlines from earlier input.<\/li>\n<li>The same variable is printed twice: <code>%c<\/code> shows it as a character, and <code>%d<\/code> shows the number stored inside it, which is the ASCII value.<\/li>\n<\/ol>\n<h2>Program 2: Find the Character from an ASCII Value<\/h2>\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nint main(void) {\n    int code;\n\n    printf(\"Enter an ASCII value (32 to 126): \");\n    scanf(\"%d\", &amp;code);\n\n    printf(\"The character for %d is %cn\", code, code);\n    return 0;\n}<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>Enter an ASCII value (32 to 126): 97\nThe character for 97 is a<\/code><\/pre>\n<p>Values 32 to 126 are the printable characters. Values 0 to 31 and 127 are control characters and do not show anything useful on screen.<\/p>\n<h2>Program 3: ASCII Values of All Characters in a String<\/h2>\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nint main(void) {\n    char str[] = \"Hi!\";\n\n    for (int i = 0; str[i] != '\u0000'; i++) {\n        printf(\"%c = %dn\", str[i], str[i]);\n    }\n    return 0;\n}<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>H = 72\ni = 105\n! = 33<\/code><\/pre>\n<p>The loop stops at <code>'\u0000'<\/code>, the null character with ASCII value 0, which marks the end of every C string.<\/p>\n<h2>Program 4: Print an ASCII Table<\/h2>\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nint main(void) {\n    for (int code = 65; code &lt;= 70; code++) {\n        printf(\"%c = %dn\", code, code);\n    }\n    return 0;\n}<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>A = 65\nB = 66\nC = 67\nD = 68\nE = 69\nF = 70<\/code><\/pre>\n<p>Change the loop to run from 32 to 126 to print every printable ASCII character.<\/p>\n<h2>Program 5: Convert Lowercase to Uppercase Using ASCII<\/h2>\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nint main(void) {\n    char ch = 'a';\n\n    if (ch &gt;= 'a' &amp;&amp; ch &lt;= 'z') {\n        ch = ch - 32;     \/* 'a' (97) becomes 'A' (65) *\/\n    }\n    printf(\"%cn\", ch);\n    return 0;\n}<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>A<\/code><\/pre>\n<p>In real programs, the <code>toupper()<\/code> and <code>tolower()<\/code> functions from <code>&lt;ctype.h&gt;<\/code> do this more safely.<\/p>\n<h2>Common Mistakes<\/h2>\n<ul>\n<li><strong>Printing with <code>%c<\/code> and expecting a number.<\/strong> Use <code>%d<\/code> for the ASCII value.<\/li>\n<li><strong>Using <code>scanf(\"%c\", ...)<\/code> after another <code>scanf<\/code>.<\/strong> It may read the leftover newline (value 10). Add a space: <code>\" %c\"<\/code>.<\/li>\n<li><strong>Confusing the digit &#8216;5&#8217; with the number 5.<\/strong> The character <code>'5'<\/code> has ASCII value 53. To get the number, write <code>ch - '0'<\/code>.<\/li>\n<li><strong>Expecting ASCII values for symbols like \u20b9 or Hindi letters.<\/strong> These are not part of ASCII. They are stored in several bytes using Unicode (UTF-8).<\/li>\n<\/ul>\n<h2>Frequently Asked Questions<\/h2>\n<h3>What is the ASCII value of A and a?<\/h3>\n<p><code>A<\/code> is 65 and <code>a<\/code> is 97.<\/p>\n<h3>What is the ASCII value of 0?<\/h3>\n<p>The character <code>'0'<\/code> is 48. The null character <code>'\u0000'<\/code> is 0.<\/p>\n<h3>Which format specifier prints the ASCII value in C?<\/h3>\n<p><code>%d<\/code>. It prints the integer stored in the <code>char<\/code> variable.<\/p>\n<h3>How many characters are there in ASCII?<\/h3>\n<p>128 (values 0 to 127). &#8220;Extended ASCII&#8221; tables use 128 to 255, but those characters differ from system to system.<\/p>\n<p>Related: <a href=\"https:\/\/gyanipandit.com\/programming\/reverse-a-string-in-c-using-strrev-function\/\">Reverse a string in C<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every character in C is stored as a small integer. For ordinary English letters, digits and symbols, that integer is the character&#8217;s ASCII value. So finding the ASCII value in C is easy: read the character into a char variable and print it with %d instead of %c. What Is ASCII? ASCII stands for American &#8230; <a title=\"How to Find ASCII Value in C (5 Programs with Output)\" class=\"read-more\" href=\"https:\/\/gyanipandit.com\/programming\/how-to-find-ascii-value-in-c\/\" aria-label=\"Read more about How to Find ASCII Value in C (5 Programs with Output)\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[29,48],"class_list":["post-4331","post","type-post","status-publish","format-standard","hentry","category-c-program","tag-c-program","tag-how-to-find-ascii-value-in-c"],"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=4331"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4331\/revisions"}],"predecessor-version":[{"id":6152,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4331\/revisions\/6152"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=4331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=4331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=4331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}