Unit 2 Elements of C
Character set:
1
C programming @Bindu Aryal
C Tokens:
1. Keywords
2. Identifiers
3. Constant
4. Variable
1. Keywords
2. Identifiers:
2
C programming @Bindu Aryal
3
C programming @Bindu Aryal
Variables:
4
C programming @Bindu Aryal
Constants:
Constant is any value that cannot be changed during program execution. In C, any
number, single character, or character string is known as a constant. A constant is
an entity that doesn’t change whereas a variable is an entity that may change. For
example, the number 50 represents a constant integer value. The character string
"Programming in C is fun.\n" is an example of a constant character string.
Types of constant:
Numeric constant
5
C programming @Bindu Aryal
Character constant
String constant
Numeric constant:
Numeric constant consists of digits. It required minimum size of 2 bytes and
max 4 bytes. It may be positive or negative but by default sign is always
positive. No comma or space is allowed within the numeric constant and it
must have at least 1 digit. The allowable range for integer constants is -32768
to 32767. Truly speaking the range of an Integer constant depends upon the
compiler. For a 16-bit compiler like Turbo C or Turbo C++ the range is –32768
to 32767. For a 32-bit compiler the range would be even greater. Mean by a
16-bit or a 32- bit compiler, what range of an Integer constant has to do with
the type of compiler. It is categorized a integer constant and real constant. An
integer constants are whole number which have no decimal point. Types of
integer constants are:
Decimal constant: 0-------9(base 10)
Octal constant: 0-------7(base 8)
Hexa decimal constant: 0----9, A------F(base 16)
Real constant:
It is also called floating point constant. To construct real constant we must
follow the rule of
real constant must have at least one digit.
It must have a decimal point.
It could be either positive or negative.
Default sign is positive.
No commas or blanks are allowed within a real constant.
Ex.: +325.34 ,426.0 -32.76
Character constant
6
C programming @Bindu Aryal
Character constant represented as a single character enclosed within a
single quote. These can be single digit, single special symbol or white
spaces such as ‘9’,’c’,’$’, ‘ ’ etc. Every character constant has a unique
integer like value in machine’s character code as if machine using ASCII
(American standard code for information interchange). Some numeric value
associated with each upper and lower case alphabets and decimal integers
are as:
A------------ Z ASCII value (65-90)
a-------------z ASCII value (97-122)
0-------------9 ASCII value (48-59)
; ASCII value (59)
String constant
Set of characters are called string and when sequence of characters are
enclosed within a double quote (it may be combination of all kind of
symbols) is a string constant. String constant has zero, one or more than
one character and at the end of the string null character (\0) is
automatically placed by compiler. Some examples are “,sarathina” , “908”,
“3”,” ”, “A” etc. In C although same characters are enclosed within single
and double quotes it represents different meaning such as “A” and ‘A’ are
different because first one is string attached with null character at the end
but second one is character constant with its corresponding ASCII value
is 65.
7
C programming @Bindu Aryal
Comments:
2.6 Type Conversion:
The format specifiers are used in C for input and output purposes. Using this
concept the compiler can understand that what type of data is in a variable during
taking input using the scanf () function and printing using printf () function. Here is
a list of format specifiers.
%c= a single character
8
C programming @Bindu Aryal
Escape Sequence:
Delimiters in C:
A delimiter is a unique character or string that marks the start or stop of a particular statement,
string, or function body set.
Programming languages employ delimiters to define code set characters or data strings,
operate as data and code boundaries, and make it easier to comprehend code and divide up
distinct implemented data sets and functions.
One or more characters that divide text strings are known as delimiters. Commas (,),
semicolons (;), quotes (", "), braces ({}), pipes (|), and slashes (/) are common delimiters. A
program uses a predetermined character to delimit each piece of data while storing sequential
or tabular data.
Examples of delimiters include:
Using parentheses or round brackets: ( )
Using curly brackets: { }
Escape code or comments: /*
Double quotes are used to define string literals: " "
9
C programming @Bindu Aryal