Showing ASCII number of alphabet letter in C


To create string in C, we commony we use char. For example :

1
char alphabet = "a"

At this point, char in C basically represents a byte. So yes, “a” equal with one byte. Just remember, everything you see char in C it’s mean byte.

Another things we should know is string structure in C is array. It have null “” for detecting the end of string. This may have different approach with other programming language.

Now, we can find out print ASCII number from given letter of alphabet in C by :

1
2
3
4
5
6
7
8
9
10
11
#include<stdio.h>

int main() {
    char alphabet;

    alphabet = ‘a’;
    /* Use %c to type of char and %d to print ASCII number */
    printf("This is ‘%c’ with number in ASCII %dn", alphabet, alphabet);

    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.