C programming constants and variables
In this post we will know today what are constants and variables in C language, how many types are there and what are the rules for writing them. So let's start ..
C Constants | My CS Tutorial |
Constant
Characters, numbers, and special symbols, when properly formed, form constants, variable and keywords.
"A constant is a quantity that does not vary.This amount can be stored at some place in the computer's memory."
C constants can be divided into two major categories:
- Primary constants
- Secondary constants
Primary consonants:
Integer,real,character consonant
Secondary consonant:
Array,pointer, structure, union, enum.etc
At this stage we will limit our discussion to only the primary constants integer, real and character constants.
Rules for Integer Constants
- The integer constant should have at least one digit.
- It should not have a decimal point.
- It can be positive or negative.
- If a signal does not increase the integer constant, then it is considered positive.
- No commas or spaces are allowed inside the integer constants.
- Acceptable range for the integer constant is -32768 to 32767.
Ex.: 625
-7605
Rules for Real Constants
The real constants are often called floating point constants.
- The real constant should have at least one digit.
- It must have a decimal point.
- It can be positive or negative.
- If a signal does not increase the integer constant, then it is considered positive.
- No commas or spaces are allowed inside the integer constants.
-47.7865
Rules for Character Constants
- A character constant is a single alphabet, single digit, or a single special symbol, which is enclosed within a single inverted commas, both inverted commas should be placed on the left side.
- The maximum length of a character constant can be 1 character.
'8'
'='
C variables
In C language, the amount that can change during program execution is called a variable.Variable names are names given for location in memory of computer where different constants are stored. In these places, the integer, the real or the characters can be fixed. In any language, types of variables that can support it can depend on the types of continuous that can handle.
Ex.: real variable name must be real constant.
Rules for Variables Names
- Variable name is a combination of alphabet, number or underscores.
- The first character of a variable name should be an alphabet.
- No spaces or commas are allowed in any variable name.
- Only a special symbol is used in the variable name which is underscores ( _ ).
No comments:
Post a Comment