The following Slide explains about the conventions and rules of Constants and Variables in C programming.
Size: 49.61 KB
Language: en
Added: Jun 16, 2014
Slides: 9 pages
Slide Content
Constants and Variables in C programming Chitrank Dixit
Constants Any unchanged value in a program during the program execution is called constant. Following are the constants in C language. Numeric Constants String or Character Constants.
Numeric Constants Integer Constant An integer constant is a signed or unsigned whole number . Example: - 23 + 356 46 C language supports an integer constant in octal (base 8) , decimal (base 10) and hexadecimal (base 16). The default number system followed in C language is decimal (base 10 ). An octal number is preceded by zero ( ) and a hexadecimal number is preceded by 0x or 0X .
Real or floating point constant : Any signed or unsigned number with fractional part is called real or floating point constant. A real constant can be written in decimal or exponential form . Example Decimal Form 0.254 +342.0 -3.15 Exponential Form 0.218e6 0.42e-32 -1.0e12 ( 0.218e6 means --> 0.218 x 10^6 and so on for all )
String or Character Constants Any string of characters enclosed in apostrophes or quotes is called string constant or character constant. There are two types of string constants . Single Character String Constant String of Characters Constant
Single Character String Constant Any letter or character enclosed in single apostrophe is called single character string constant. Example: 'y' '$' '+'
String of Characters Constant Any string of characters consisting of letters, digits and symbols enclosed in double quotes is called string of characters constant . Example : "Total value is“ , “12 vyas fala ”, “value is = “
Variables A variable is an identifier or a name which is used to refer a value and this value varies or changes during the program execution. A variable is written with a combination of letters , numbers and special characters _(underscore) with the first letter being an alphabet. Maximum of 31 letters can be used to write a variable . Example: x , fact , c22 , total_value
Important rules while writing a variable in C Programming Upper and Lower case alphabets are taken differently, so the variables SUM and sum are referring to different values. No special characters other than underscore ( _ ) are permitted . Some C compilers will not accept more than 8 characters. So it is a good practice writing a variable with few letters which makes it also convenient to write and use All variables used in a C program are declared with appropriate data types before the variable is assigned any value . Reserved words cannot be used as variables.