C Programming1
C Programming1
C Programming1
1. Keywords
2. Identifiers
3. Constants
4. Operators
5. Special symbols
KEYWORDS
The tokens which have predefined meaning in C language are called keywords.
They are reserved for specific purpose in C language they are called as Reserved
Words. There are totally 32 keywords supported in C they are:
auto ,double, if ,static ,break ,else, int ,struct, case, enum, long ,switch ,char,
extern,near etc.
Rules for keywords
1. Keywords should not be used as variables ,function names, array names etc.
2. All keywords should be written in lowercase letters.
3. Keywords meaning cannot be changed by the users.
IDENTIFIERS
Identifiers are the names given to program elements such as variables, constants,
function names, array names etc
It consists of one or more letters or digits or underscore.
1. Integer constant
2. Real constant/Floating Pointing constant
3. Enumeration constant
4. Character constant
5. String constant
1. INTEGER CONSTANT
An integer is whole number without any decimal point. no extra characters are
allowed other than + or - .
Three types of integers
1) Decimal integers: are constants with a combination of digits 0 to 9,optional + or -
Ex: 123 , -345, 0 , 5436 , +79
2)Octal integers: are constants with a combination of Digits from 0 to 7 but it has a
prefix of 0
Ex: 027xo , 0657 , 0777645
3)Hexadecimal integers: Digits from 0 to 9 and characters from a to f, it has to start
with 0X or 0x Ex: 0X2 0x56 0X5fd 0xbdae
2. REAL CONSTANTS/FLOATING POINT
Floating point constants are base 10 numbers that are represented by fractional parts, such as
10.5.They can be positive or negative.
Two forms are:
1)Fractional form:
A floating point number represented using fractional form has an integer part followed by dot
and a fractional part.
Ex: 0.0083 , 215.5 -71 , +0.56 etc..
2) Exponential form:
A floating point number represented using Exponent form has 3 parts
mantissa e exponent ,mantissa is either real number expressed in decimal notation or integer.
Exponent must be integer with optional + or -
Ex 9.86 E 3 => 9.86*103 ,9.86 E -3 => 9.86*10-3
3. ENUMERATION CONSTANT
A set of named integer constants defined using the keyword enum are called
enumeration constants.
Syntax: enum Identifier{enum list};
Ex:
1) enum Boolean{NO,YES};
NO is assigned with 0
YES is assigned with value 1
2) enum days{ mon,tue.wed};
mon is assigned with 0
true is assigned with 1
wed is assigned with 2
4.CHARACTER CONSTANT
A symbol enclosed within pair of single quotes is called character constant.
Each character is associated with unique value called ASCII value.
It always start with backslash ,hence they are called as backslash constants.
CHARACTER NAME MEANING
\\ Backslash Backslash
\0 NULL
5.STRING CONSTANT
A sequence of characters enclosed within pair of double quotes is called
string constant.
The string always ends with a NULL character. Ex: “9 \0” , “SVIT”
Special char
2. Derived Datatypes
1. Short int
2. Int
3. Long int
2. FLOATING DATA TYPE (FLOAT):
An float is a keyword using which the programmer can inform the compiler
that the data associated with this keyword should be treated as floating point
number.
The size is 4 bytes.
Float can hold the real constant accuracy up to 6 digits after the decimal
point.
3.DOUBLE DATA TYPE (DOUBLE):
An double is a keyword using which the programmer can inform the
compiler that the data associated with this keyword should be treated as long
floating point number.
The size is 8 bytes.
Double can hold real constant up to 16 digits after the decimal point.
4.CHARACTER DATA TYPE (CHAR):
char is a keyword which is used to define single character or a sequence of
character in c language capable of holding one character from the local
character set.
The size of the character variable is 1 byte.
Variables are not initialized when they are declared and defined, they contain garbage
values(meaningless values)
The method of giving initial values for variables before they are processed is called variable
initialization.
General Syntax:
Var_name = expr;
Where, Var_name is the name of the variable ,
expr is the value of the expression.
The “expr” on the right hand side is evaluated and stored in the variable name (Var_name) on left hand
side.
The expression on the right hand side may be a constant, variable or a larger formula built from simple
expressions by arithmetic operators.
Examples: int a=10; // assigns the value 10 to the integer variable a
float x; x=20; // creates a variable y of float type and assigns value 20 to it