Thursday, May 29, 2014

C KeyWords


C Keywords  :
The C language reserves certain words that have special meanings to the language. Those reserved words are sometimes called C keywords. You should not use the C keywords as variable, constant, or function names in your program. The following are the 32 reserved C keyword.
Keyword
Description
auto
Storage class specifier
break
Statement
case
Statement
char
Type specifier
const
Storage class modifier
continue
Statement
default
Label
do
Statement
double
Type specifier
else
Statement
enum
Type specifier
extern
Storage class specifier
float
Type specifier
for
Statement
goto
Statement
if
Statement
int
Type specifier
long
Type specifier
register
Storage class specifier
return
Statement
short
Type specifier
signed
Type specifier
sizeof
Operator
static
Storage class specifier
struct
Type specifier
switch
Statement
typedef
Statement
union
Type specifier
unsigned
Type specifier
void
Type specifier
volatile
Storage class modifier
while
Statement

Note that : All C keywords are written in lowercase letters. As I’ve mentioned, C is a case-sensitive language. Therefore, int, as shown in the list here, is considered as a C keyword, but INT is not.


The char Data Type

The char Data Type
An object of the char data type represents a single character of the character set used by your computer. For example, A is a character, and so is a. But 7 is a number.
But a computer can only store numeric code. Therefore, characters such as A, a, B, b, and so on all have a unique numeric code that is used by computers to represent the characters. Usually, a character takes 8 bits (that is, 1 byte) to store its numeric code.
For many computers, the ASCII codes are the de facto standard codes to represent a character set. (ASCII, just for your information, stands for American Standard Code for Information Interchange.) The original ASCII character set has only 128 characters because it uses the lower 7 bits that can represent 27 (that is, 128) characters.

On IBM-compatible PCs, however, the character set is extended to contain a total of 256 (that is, 28) characters. Appendix C, “ASCII Character Set,” gives a list of the 256 characters.

Character Variables
A variable that can represent different characters is called a character variable.
You can set the data type of a variable to char by using the following declaration format:

char  variablename;
where variablename is the place where you put the name of a variable.
If you have more than one variable to declare, you can either use the following format:
char  variablename1;
char  variablename2;
char  variablename3;
or this one:
char  variablename1, variablename2, variablename3;

Character Constants
A character enclosed in single quotes (`) is called a character constant. For instance, `A’, `a’, `B’, and `b’ are all character constants that have their unique numeric values in the ASCII character set.
You can remember to use the single quote (`), instead of the double quote (“), in character constants because a character constant represents a single character. You’ll see later in the book that the double quote is used to indicate a string of characters.
From the ASCII character set listed in Appendix C, you will find that the unique numeric (decimal) values of `A’, `a’, `B’, and `b’ are 65, 97, 66, and 98, respectively. Therefore, given x as a character variable, for instance, the following two assignment statements are equivalent:

x = `A';
x = 65;

So are the following two statements:

x = `a';
x = 97;

The Escape Character (\)
Actually, you first saw the escape character (\) in Hour 2, “Writing Your First C Program,” when you learned to use the newline character (\n) to break a message into two pieces. In the C language, the backslash (\) is called the escape character; it tells the computer that a special character follows.

For instance, when the computer sees \ in the newline character \n, it knows that the next character, n, causes a sequence of a carriage return and a line feed.

Besides the newline character, several other special characters exist in the C language, such as the following:

Character
Description
\b
The backspace character; moves the cursor to the left one character.
\f
The form-feed character; goes to the top of a new page.
\r
The return character; returns to the beginning of the current line.
\t
The tab character; advances to the next tab stop.

 Printing Out Characters
You already know that the printf() function, defined in the C header file stdio.h, can be used to print out messages on the screen. In this section, you’re going to learn to use the character format specifier, %c, which indicates to the printf() function that the argument to be printed is a character. Let’s first have a look at the program in Listing 4.1, which prints out characters on the screen.

TYPE

Later in this hour, you’ll see a program (in Listing 4.2) that converts numeric values back to the corresponding characters.
http://www.programalgorithms.blogspot.com/

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home