Getting started with C Programming: Constants and variables in C: Study C in 7 days

3rd Day


Different types of constants and variables are 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 Digits
Upper case letters A to Z
Lower case letters a to z
Decimal digits 0 to 9


Special characters
The special characters are 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
    %      Percentage

Numeric 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 are 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 constants. 
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 be start with letter 
  • Cannot be 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

C Programs Beginner Guide

 

Copyright © 2011 CircuitsGallery| ToS | Privacy Policy | Sitemap

Contact Us | Write For Us | Advertise on Circuits Gallery | About Us