Right Click to Search

Saturday, January 16, 2025

Arithmetic Operations On Character in C Programming


Arithmetic Operations On Character :
  • C Programming Allows you to Manipulate on String
  • Whenever the Character is variable is used in the expression then it is automatically Converted into  Integer Value called ASCII value
  • All Characters can be Manipulated with that Integer Value.(Addition,Subtraction)
Examples :
  1. ASCII value of : 'a' is 97
  2. ASCII value of : 'z' is 121

Possible Ways of Manipulation :
Way 1: Displays ASCII value[ Note that %d in Printf ]
char x = 'a';
printf("%d",x); // Display Result = 97
Way 2 : Displays Character value[ Note that %c in Printf ]
char x = 'a';
printf("%c",x); // Display Result = a
Way 3 : Displays Next ASCII value[ Note that %d in Printf ]
char x = 'a' + 1 ;
printf("%d",x);
// Display Result = 98 ( ascii of 'b' )
Way 4 Displays Next Character value[Note that %c in Printf ]
char x = 'a' + 1;
printf("%c",x); // Display Result = 'b'
Way 5 : Displays Difference between 2 ASCII in Integer[Note %d in Printf ]
char x = 'z' - 'a';
printf("%d",x);
/* Display Result = 25 
    (difference between ASCII of z and a ) */
Way 6 : Displays Difference between 2 ASCII in Char [Note that %c in Printf ]
char x = 'z' - 'a';
printf("%c",x);
/* Display Result = ↓ 
      ( difference between ASCII of z and a ) */

Tags / Keywords : | ,

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates