8. CONSTANTS :
Constant : A value that anyone can’t change during execution of the program and therefore remains persistent throughout the program.
Constants can be classified into three types :
- NUMERIC CONSTANT
- CHARACTER CONSTANT
- STRING CONSTANT
NUMERIC CONSTANTS :
First of all, Numeric constants are the constants containing numeric digits. The numeric digits may or may not have decimal point.
The rules for defining numeric constants are :
- At least 1 digit should be present in a numeric constant.
- Within the numeric constant, no comma or space should be there.
- Numeric constants can either be positive or negative but default sign is always positive.
There are two types of numeric constants :
- INTEGER CONSTANT
- REAL CONSTANT
- INTEGER CONSTANT :-
The whole numbers having no decimal point are Integer constants.
On the basis of different number systems, Integer constants are classified in three types that are –
- DECIMAL CONSTANTS – 0,1,2,3,4,5,6,7,8,9 (base 10)
- OCTAL CONSTANTS – 0,1,2,3,4,5,6,7 (base 8)
- HEXADECIMAL CONSTANTS – 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,a,b,c,d,e,f (base 16)
- REAL CONSTANTS :-
Real constants or floating point constants are numeric constants containing decimal point. Some of the valid floating point constants are –
CHARACTER CONSTANTS :
When a single character encloses within single quotes is known as a Character constant. Some valid character constants are –
- ‘ ‘
Some invalid character constants are –
- ‘Program‘ – Invalid because only one character should be present within quotes.
- “M” -Invalid because Double quotes don’t enclose single character.
- ‘ ‘ – Invalid because no character between single quotes
- U – Invalid because single quotes missing
STRING CONSTANTS :
A string constant contains zero, one or more than one character. Unlike a character constant, a string constant encloses within double quotes (” “). At the end of the string, the compiler automatically places ‘\0’ or null Character at that place.
Some examples of valid string constants are –
- “Mukul Bhatt”
- ” “
NOTE – “A” and ‘A’ are different from each other. The first one is a string constant which consists character ‘A’ and ‘\0’. In contrast, the second one is a character constant which represents integer value 65.
9. VARIABLES :
To define a variable, it is a name that we can use to store values. Furthermore, Variables can take different values but almost one at a time. We can change values taken by variables while execution of the program.
With each variable, a data type is associated. The data type of the variable decides what type of value it will take. Some examples of valid variables are –
- int a; //Where int is an integer data type and a is the name of the variable.
- float c; //Where float is floating data type and c is the name of the variable.
10. EXPRESSIONS :
A combination of operators, constants, variables and function calls is known as an expression. The expression can be arithmetic, logical or relational. Some examples of different types of expressions are as follows –
- x+y – arithmetic operation
- a>b – relational expression
- func(a, b) – function call
11. STATEMENTS :
In a C program, the instructions we write are in the form of statements. Furthermore, an executable part of the program through which the computer carry out some action is therefore a statement.
The classification of statements are as follows –
- EXPRESSION STATEMENTS
- COMPOUND STATEMENTS
- SELECTION STATEMENTS
- ITERATIVE STATEMENTS
- JUMP STATEMENTS
- LABEL STATEMENTS
12. COMMENTS :
The comment lines or comments have almost specific uses in a Program. Hence, we use comments in the documentation section of a program. The General purpose of using Comments is increasing readability of the program. The proper format under which comments are written is “/*” and “*/”. One can write comments anywhere in a program except inside a string constant or character constant.
Generally, comments are of two types –
- SINGLE LINE COMMENTS
- MULTIPLE LINE COMMENTS
NOTE : AS A RESULT, COMMENTS CAN’T BE NESTED because we cannot write a comment inside another comment.
Hence, it was all about THE C ELEMENTS Or THE ELEMENTS OF C LANGUAGE.
For more detailed information regarding the previous post, Click on