Tuesday, January 5, 2010

Character Variable

The previous post is variable for a number.
How if the variable is a letter? It’s very simple, just define the type and the name of the variable first, like a number variable.

See the example below:

#include "iostream.h"
#include "conio.h"
main ()
{
char word;
word ='r';
cout<<"The character (letter) is: ";
cout<< word;

getch();
}


see this picture:


Char is a type of variable for character (letter)
The name of the variable here is word, and it’s value is r (between ‘ ‘)
Just rewrite the complete syntax above, then run the program, and we will see the result.

0 comments:

Post a Comment