Find the ASCII value of the uppercase character ‘A’ using implicit conversion in C language?

CServer Side ProgrammingProgramming

Implicit type conversion is done by the compiler by converting smaller data type into a larger data type.

For example, ASCII value of A=65.

In this program, we are giving character ‘A’ as input, now write a code to convert A to 65 which is its ASCII value.

Example

Following is the example to find ASCII value of uppercase character ‘A’ using implicit conversion −

 Live Demo

#include<stdio.h>
int main(){
   char character = 'A';
   int number = 0, value;
   value = character + number; //implicit conversion
   printf("The ASCII value of A is: %d\n",value);
   return 0;
}

Output

The ASCII value of ‘A’ is 65. Using typecasting in C, the compiler automatically converts the character of char data type into the integer data type and the expression(value = character + number) becomes equal to 65 + 0 = 65

Therefore, the output would be 65.

The ASCII value of A is: 65

Example

Let us consider example by taking another character and see what is the ASCII value of that character.

 Live Demo

#include<stdio.h>
int main(){
   char character = 'P';
   int number = 0, value;
   value = character + number; //implicit conversion
   printf("The ASCII value of P is: %d\n",value);
   return 0;
}

Output

The ASCII value of ‘P’ is 80. Using typecasting in C, the compiler automatically converts the character of char data type into the integer data type and the expression (value = character + number) becomes equal to 80 + 0 = 80

Therefore, the output would be 80.

The ASCII value of P is: 80
raja
Published on 08-Mar-2021 12:54:46
Advertisements