Constants Variables and Data Types
Constants Variables and Data Types
KEYWORDS
CONSTANT KEYWORDS IDENTIFIERS SPL SYMBOLS STRINGS OPERATORS
Every c word is classified as a keyword and identifiers. all the keywords have fixed meaning and the
value of it cannot be changed.
IDENTIFIERS
All the keywords should be written in lowercase letters.
Identifiers refer to the names of variables functions arrays.
These are user defined names, and consist of sequence of letters, digits, with first characters as a letter.
Both uppercase and lowercase letters can be used, although lowercase letters are commonly used.
The underscore character is also permitted in identifiers; it is usually used as a link between two words
in long identifiers.
RULES FOR IDENTIFIER
1. First character should be an alphabet or underscore can be used.
2. Must only contain letters, digits, or underscore.
3. Can’t use keyword.
4. Only 31 characters are included.
CONSTANTS
5. Must not contain white space.
Constant in a c refers to the fixed value that doesn’t change during the execution of a program. C
supports several types of constant as illustrated below.
CONSTANTS
INTEGER CONSTANT
INTEGER CONSTANT REAL CONSTANT SINGLE CHARACTER STRING CONSTANT
It refers to the sequence of digits. There are three types of integer constant namely.
1. Decimal constant
2. Octal constant
3. Hexadecimal
Decimal integer refers to digits from 0-9, preceded by negative or positive sign valid.
Eg: -331, 222, 931, and 432
Embedded spaces, commas, and non digit character are not permitted digits.
Eg: 15750, 20,000 $1000 are illegal numbers.
An octal integer refers to any combination of numbers from 0-7, leading with 0.
The numbers preceding OX or ox are called as Hexadecimal numbers. They may contain alphabet also
from A through F or a through f.
The alphabet from A through F or a through f represents the number from 10-15.
Eg: OX2, OX9F, OXBCD, OX
REAL CONSTANT
Integer numbers are inadequate to represent quantities that vary continuously such as distances,
heights, temperatures, prices and so on. These quantities are represented by number containing
fractional parts like 17.548.
Such numbers are called real(floating point) constants further
0.0083, -0.75, 435.36
A real number may also be expressed in exponential (scientific) notation.
SINGLE CHARACTER CONSTANT
In exponential notation as the power increases it number of zero increases
A single character constant contains a single character enclosed with single quotation marks.
Eg: ‘5’ ‘x’ ‘’
Note that the character constant ‘5’ is not same as the number 5, the last constant is a blank space.
Character constants have integer values known as ASCII value.
For Eg: the statement printf (“%d”, ‘a’);
Would print the number 97, the ASCII value of letter a. similarly, the statement printf (“%c”, ‘97’);
Would output the letter ‘a’.
STRING CONSTANT
A string constant is a sequence of characters enclosed in double quoted marks. It can contain letters,
digits, blank spaces etc
Eg: “hello” “123” “x”
BACKSLASH CHARACTER CONSTANT
C supports some special backslash character constant that are used in output functions
Eg:
‘\a’ audible alert
‘\b’ backspace
‘\f’ form feed
‘\n’ new line
‘\r’ carriage return
‘\t’ horizontal tab
‘\v’ vertical tab
‘\?’ question mark
‘\’’ single quote
‘\’’’ double quote
‘\\’ backslash
‘\0’ null
VARIABLE
A variable is a dataname that may be used to store a data value, unlike constants that remains
unchanged during the execution of a c program.
Variable can be created by the programmer so as it reflects its function/nature in the program.
A variable take variable at different
RULE FOR VARIABLE
1. A variable should begin with a letter, and some system support underscore as 1 st character.
2. A variable should consist 31 character are significant. Only first 31 characters are included.
3. A variable can consist of uppercase and lowercase letters.
4. White spaces are not allowed in variables.
5. A variable shouldn’t be a keyword.
DATA TYPES
Definition is to be written from google
ANSI C supports three classes of data types
1.Primary data type
2.Derived data type
3.User defined data type
All the c compilers support five fundamental data types namely integer (int), character (char), floating
point (float), double-precision floating point (double) and void.
Many of them also offer extended data types such as long int and long double
PRIMARY DATA TYPES
INTEGRAL TYPE
INTEGER CHARACTER
FLOAT DOUBLE
DATA TYPE RANGE OF VALUES
LONG DOUBLE VOID
CHAR -128 TO 127
INT -35,768 TO 32,767
FLOAT 3.4e-38 TO 3.4e+38
DOUBLE 1.7e-308 TO 1.7e+308
INTEGER TYPES
Integers are the whole numbers with a range of values supported by a particular machine.
Generally integers occupy one word of storage, and since the word sizes of machine vary
( typically 16 or 32 bits).
The size of the integer that can be stored depends on the computer.
C has three classes of integer storage, namely short int, int and long int , in both signed and
unsigned forms.
FLOAT
DOUBLE
LONG DOUBLE