Sunday, 21 January 2018

Arithmetic Operations On Characters


Arithmetic Operations On Characters

Arithmetic Operations On Characters
'C' allows us to manipulate characters in the same way we do with numbers.Whenever a character constant or character variable is used in an expression , it is automatically converted to integer value by the system .Integer value depends on local character set of the system .
     If the machine uses the ASCII representation then
                     x = 'a';
                     printf("%d", x);
 will display the number 97 on the screen.

ex: x = 'z'-1; is a valid statement
In ASCII , the value of 'z' is 122 , therefore the value
121 is assigned to x.
  The 'c' library supports a function that converts a string
of digits into their integer values .
   The function takes the form
         x = atoi(string);
     x is an integer variable and string is a character
array containing a string of digits.
ex:            ------------------
                 number = "1988";
                 year = atoi(number);
The function converts the string "1988" to its numeric
equivalent 1988 and assigns it to the integer variable year

Related Posts:

  • Limitations of array Pointers to stringsLimitations of array Pointers to stringsWhen we are using a two-dimensional array of characters we are at liberty to either initialize the strings where we are declaring the array, or receive the stringsusing scanf() function… Read More
  • Two Dimensional Array Of CharactersTwo Dimensional Array Of CharactersOur example program asks you to type your name.When you do so,it checks against a master list to see if you are worthy of entry to the palace.Example:    #include "string.h"&n… Read More
  • Basic PointersBasic PointersPointer Definition: Pointer is a variable which contains the address of another variable.Reasons for using pointer:1.A pointer enables us to access a variable that isdefined outside the function.2.Pointers are m… Read More
  • Array Of Pointers To StringsArray Of Pointers To StringsAs we know , a pointer variable always contains an address. Therefore , if we construct an array of pointers it would contain a number of addresses.Let us see how the names in the earlier example c… Read More
  • Pointers And StringsPointers And Strings    We cannot assign a string to another,whereas we can assigna char pointer to another char pointer. This is shown with an example:main(){ char str1[]="hello"; char str2[10]; char… Read More

0 comments:

Post a Comment