Constants in C programming (3rd Day)
It's our third day of learn C online in 7 days tutorial. Don't hesitate to ask for any basic C programming help if there's any trouble with the last 2 days tutorial. Today we will be dealing with different types of constants and variables used in C program. For example- Characters, Letters, Special characters, symbols, numbers, etc. Here we are discussing about constants and variables. To use the constants and variable in C, we must follow the basic syntax rules. This article covers the essential constants and variables in detail.Characters
Letters and DigitsUpper case letters A to Z
Lower case letters a to z
Decimal digits 0 to 9
Special characters
The special characters used in C programming are:
, Comma
& Ampersand
. Period
* Asterisks
; Semicolon
: Colon
- Minus sign
+ Plus sign
? Question mark
^ Caret
‘ Apostrophe
“ Quotation mark
! Exclamation mark
| Vertical bar
/ Slash
\ Back slash
~ Tilt
$ Dollar sign
_ Underscore
# Number sign
< Opening
angle bracket
> Closing
angle bracket
( Left parenthesis
) Right parenthesis
[ Left bracket
] Right bracket
{ Left brace
} Right brace
% PercentageNumeric Constants
Different types of numbers are included in numeric constants.Decimal Integer
0 to 9 numbers are used.
eg: -12, 13
Octal integer
0 to 7 numbers are used.
eg: 026, 054
(Octal number should start with zero; it is the syntax of representing in C language).
Hexa decimal integer
0 to 9 and A to F values are used.
eg: 0x12, 0x4F
(Hexa decimal number should starts with zero x (0x), it is the syntax of representing in C language).
Real constants
All the real numbers comes under this category.Eg: -5.67, 480 etc.
Character Constant
The 26 letters are used for character constants. There are two types of character constants in C:Single character constants
A single character included inside a single quotation is called single character constant.
Eg: ‘A’, ‘B’ etc
String constants
The group of letters included inside a double quotation is called string constants. A string constant ends with ‘\0’ (Null). We can use letters, numbers, special characters, blank space in a string.
Eg: “i-St@r Group 2012”.
Back slash character constants
\n to start new line\t Horizontal tab
\v Vertical tab
Variables
Variable is used to store a value. This value will change according to different situations while the program is executing.Rules for a variable
- Variable name should start with a letter.
- Cannot exceed 31 letters.
- Variable name is case sensitive, that is ‘a’ not equal to ‘A’.
- Variable name should not be a ‘keyword’ eg: int, float, if, else, etc.
- Blank spaces are not allowed.
Ads
0 comments:
Post a Comment