Getting started with C Language (2)
Introduction:
There are 2 nature of data: Constant and Variable
1) Constants are the data that cannot
be changed (example: PI is constant i.e. 3. 1418..)
In any program we do lot of calculations. the
results of these calculations need to stored in computer memory to retrieve
these values when required in program. for easy retrieval and usage of these
values the names are given to the memory cells called as variable names.
Rules for constructing integer constants:
- Integer
constant must contain one digit
- It
must not have a decimal digit or value
- It
can be positive or negative; if no sign mentioned default considered as
positive.
- No
commas and blanks are allowed in between the digits of number
- The
integer range can be stored is -2147483648 to +2147483647 or -32768 to +32767(depends
on compilers)
- Valid
integer constants:
- 400
- -555
- 3089
- -4096
- Invalid
integer constants:
- 50.36
- 0,88
- 0.74
Rules for constructing Real
constants:
- 400
- -555
- 3089
- -4096
- 50.36
- 0,88
- 0.74
- They
are also called as floating point constants.
- The
real constant must have at least one digit
- It
must have decimal point, if decimal point is not there it will be considered as
whole.
- Default
sign is positive
- No
commas and blanks are allowed
- Valid
examples:
- +655.6
- 888.6
- -63.36
- -7089
- Invalid
examples:
- -42,6
- -12 .0
- +655.6
- 888.6
- -63.36
- -7089
- -42,6
- -12 .0
Rules for constructing character constants:
- A
character constant is an alphabet, digit or a special character enclosed in a
single inverted comma (‘ ‘)
- Character
constants are also known as “One-byte integers”
- Valid examples:
- 'a'
- 'J'
- '8'
- '!'
- Invalid examples:
- "Z"
- 'ABCd'
- "C Language"
- 'a'
- 'J'
- '8'
- '!'
- "Z"
- 'ABCd'
- "C Language"
Primary Constants:
There are three type of variables as shown above i.e. integer, real(float), character; each type of variable can hold only the same type of value in it; integer variable can hold only integer value, real or float variable can hold only real values/floating values, character variables can hold only character constants in it.
Rules of constructing variable names:
- The
variable name can be combination of 1 to 31 alphabets, digits and underscore (only
in special character)
- It
is a good practice to sum up the variable name length to 8/9caharcters only, as
it saves writing efforts of writing much more long names and avoid errors in some
big programs.
- The
first character must be an alphabet or underscore ( _ ) only; no digit is
allowed in starting of the variable name.
- No
commas and space are allowed in variable name; it will generate error.
- No
special symbol other than underscore ( _ ) is allowed in variable name.
- Valid
variable names:
- speed_km
- C_lang1
- value1234_
- _abc
- Invalid
variable name:
- 1_speed
- info@123
- C Lang
- speed_km
- C_lang1
- value1234_
- _abc
- 1_speed
- info@123
- C Lang
Keywords:
Keywords are the special names whose
definitions are already written and explained to the c compiler
we cannot use keywords as variable
names; nor we can modify keywords; they are reserved.
There are 32 keywords in C language as below:
Comments
Post a Comment