Find ASCII value of a character in C

In this C programming guide we will write some program to find ASCII value of a character. At first we will take the character from user then print the ASCII value as like as given in the figure bellow.

ascii-value-of-character-in-c-find-ascii-value-of-character-in-c

We can find the ASCII value by a very simple program. We can also use pointer to find the value. Let’s see the program bellow;

C program to find ASCII value of character

// c program to find ASCII value of character

#include <stdio.h>

int main(){

    char given_ch;

    printf("Enter a character to find ASCII value here : ");

    scanf("%c", &given_ch);

    printf("\nASCII value of given '%c' is = %d\n", given_ch, given_ch);

    // %d will print the ASCII value of given character here
    return 0;
}

Output of ASCII value program:

Find ASCII value of character using pointer in C

// c program to find ASCII value using pointer

#include <stdio.h>

int main(){
    char *ch_ptr, given_char;

    printf("Enter a character for ASCII value here : ");

    scanf("%c", &given_char);

    ch_ptr = &given_char;

    printf("\nASCII value of given character '%c' is = %d\n", given_char, *ch_ptr);

    // %d will print the integer value of pointer ch_ptr
    return 0;
}

Program output will be as follows :

Enter a character for ASCII value here : k

ASCII value of given character 'k' is = 107

Previous pageVariable size and limit

Next pageSum of array