Getting Ready to Learn C
Like any natural language, C
computer language too has its own character set, grammar, and rules. Before
start writing programs, you should first learn these basics of C language.
C Character Set:
C computer language allows following
valid alphabets, numbers and special symbols-
A, B, ……., Z
a, b, …….., z
0, 1, …….., 9
~ `
! @ #
% ^ & *
( ) _
+ - =
| \ {
} [ ]
: ; “
‘ < > , .
? / $
C Keywords:
Keywords are the reserved words
or terms which have a special meaning. This meaning has been described to
compiler. These keywords can only be used for the purpose they are designed to.
They cannot be used for anything else. There are 32 keywords provided in the C
computer language as given below:
auto
|
break
|
case
|
char
|
const
|
continue
|
default
|
do
|
double
|
else
|
enum
|
extern
|
float
|
for
|
goto
|
if
|
int
|
long
|
register
|
return
|
short
|
signed
|
sizeof
|
static
|
struct
|
switch
|
typedef
|
union
|
unsigned
|
void
|
volatile
|
while
|
Meaning of these keywords
will be explained later wherever and whenever they are used.
Variables and Constants:
As the name suggests
variable refers to the entity that may change, and constant refers to the
entity that doesn’t change. During execution, the program resides in computer’s
memory (RAM). A program can have many data values and it does lots of
calculations during program execution. The results too are stored in this
memory. Computer memory consists of millions of cells. The data values are
stored in these memory cells. To retrieve or store these data values easily,
these memory cells or locations are given some meaningful names. These names
are called variable names. Since, one can change the values of these memory locations;
hence the name given to these locations is variable-name or variable simply. The
data values itself are called constants. For example, you refer to a memory
location by the name ‘x’, and give the value to it 5. During program execution,
you give another value 7 to ‘x’. In this example, ‘x’ is a variable, because
its value is changing and you can give different values to it at different
times. 5 and 7 are constants, because these are fixed values. Variable can be
called ‘identifiers’ and constants
can be called ‘literals’.
Types of Variables and Constants:
Variables and constants can
be organised in two broad categories-
- Primary
- Secondary
- Integer type
- Real or floating point type
- Character type
- Array
- Structure
- Union
- Enum
Variable Naming Conventions:
- A variable name can be a combination of alphabets, digits, and an underscore ( _ ) and its size can be of one character to 31 characters.
- A variable name must start with an alphabet or underscore ( _ ).
- No blanks are permitted in the variable name.
- No special character except underscore ( _ ) can be used.
- Variable names should be meaningful.
Rules for Creating Constants:
Rules for creating primary constants are given below-Integer Constant:
- There should be at least one digit in the integer constant.
- There should be no decimal point.
- An integer constant can be positive or negative.
- Default sign of integer constant is positive. If you don’t specify the sign, it is assumed to be positive.
- There should be no commas or blanks in the constant.
- The range of integer constant is from -32768 to +32767.
- For some compiler, range is from -2147483648 to +2147483647.
- Ex: 3, 56, -657, etc.
- A real constant must have a decimal point.
- There should be at least one digit before or after decimal point.
- No commas or blanks are permitted in the constant.
- By default, floating point constants are positive, but it can be either positive or negative.
- Ex: 0.5, 238.48, -65754.433, etc.
- Floating point constants can be written in exponential form too. If the number is either too small or too large, exponential form is suitable to use.
- In exponential form, the real constant is written in two parts. The first part is called mantissa, whereas second part is called exponent. These two parts are separated by the letter ‘e’ or ‘E’.
- The first part mantissa can be positive or negative. Default sign is positive.
- Thus, the number 0.000003827 can be written in exponential form as 3.827e-6. In normal mathematics it can be written as 3.827x10-6.
- The range of real constant is -3.4e38 to 3.4e38.
A character constant is any
single alphabet, or a digit, or any special symbol enclosed within single
quotation marks or apostrophes.
Ex: ‘a’, ‘6’, ‘&’, etc.
No comments:
Post a Comment