C: Display A Char's Numerical Value.


The char type in C is an integer which gets decoded as a character. You can print the char's numerical type.

https://github.com/pereiradaniel/beginning_c/blob/master/ch2/char.c

// Chars
// Daniel Pereira, 16 November 2022.

// Display a char and it's numerical value.

#include <stdio.h>

int main(int argv, char* argc[])
{
    char c = 0;
    printf("Enter a character: \n");
    scanf(" %c", &c);
    printf("The character: %c\nIt's numerical value: %d\n", c, c);

    return 0;
}
https://github.com/pereiradaniel/beginning_c/blob/master/ch2/char.txt
==87== Memcheck, a memory error detector
==87== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==87== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==87== Command: ./char
==87==
Enter a character: 
X
The character: X
It's numerical value: 88
==87== 
==87== HEAP SUMMARY:
==87==     in use at exit: 0 bytes in 0 blocks
==87==   total heap usage: 2 allocs, 2 frees, 2,048 bytes allocated
==87==
==87== All heap blocks were freed -- no leaks are possible
==87==
==87== For lists of detected and suppressed errors, rerun with: -s
==87== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Popular posts from this blog

C programming and relevancy

Shakespeare AI: My lady is more beauteous than a rose.

C: Temperature Conversion With Main Repeat