Write about Arithmetic Operations on Characters?

C allows us to manipulate characters the same way we do with numbers .

Whenever a character constant ( or) character vars is used in an expression it is automatically converted into an integer value by the system.

To write a character in its integer representation, we may write it as :

x = ‘a’;

printf ( “%d \n”, x);

display the number 97 on the screen.

It is also possible to perform arithmetic operations on the character constants.

x = 'z’–1;

In ASCII, the value of ‘z’ is 122 and there four the statement will assign the value 121 to the var x.

We may also use character constants in relational expressions.

ch > = “A” && ch < = “Z”

Would test whether the character contained in the var ch is an upper –case letter.

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 var and string is a character array containing a string of digits.

Ex: number = “1998”;
           year = atoi ( number);

The function atoi converts the string “1988” to its numeric equivalent 1988 & assigns it to the integer variable year.

String conversion functions are stored in the header file < stdlib. h>.

Related

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item