Character data types can be displayed as a character or as a number. This depends on how the writing is regarded as a character or a number. To write the contents of the data type char is to use printf with the format of writing using sign% c if you want to appear as a character or the% i if you want to appear as a number.
This data type has a range from 0 to 255, or ASCII characters to ASCII characters 0 to 255.
Giving value to a character use the following command:
The second way to produce a similar effect is to give the value of a 65 or a character to character variables. If you want to use a variable charge character of the character will be sandwiched between the input apostrophe. To see the value in a variable of type char using the following command
printf(“Karakter dilihat dalam bentuk karakter = %c.\n”,karakter);
printf(“Karakter dilihat dalam bentuk angka = %d.\n”,karakter);
char k1, k2;
"In line 6 means 2 programs booked a place in memory to store data of type character with the name of k1 and k2.Perintah"
k1 = 'A';
"On line 7 is the command to insert a character value into variable capital k1 so for the next line contains the characters A k1 capital or number 65.Perintah"
k2 = k1;
"In line 8 means that the value of k2 is filled so that the contents of k1 values equal to k2 variable content in k1.Perintah printf at line 9 is the command to display the writing in accordance with the format" variable value k1 is% c \ n ". Character% c was not printed as% c, but will be replaced by variables in accordance with the order of k1 in the form of characters. Printf command on line 10 works the same way with the printf command in line 9 the difference is only signal% d from written based on k2 variable content printed in the form of numbers rather than characters. Sign% d format is used for printing the data in the form of numbers bulat.Perintah
used to wait until the user pressing any karaker.Perintah
used to change the value of the function main ().