Revision Notes For Class FC
Revision Notes For Class FC
1. Integer - 4 bytes
Format specifier- %d
2. Float - 4 bytes
Format specifier- %f
3. Double- 8 bytes
Format specifier- %lf
4. Long double- 16 bytes
Format specifier- %Lf
5. Character- 1 byte
Format specifier- %c
Tokens-
Smallest individual element that can be easily identified by the compiler.
1. Keywords
Unique words or Reserved words
Example:
auto
switch
enum
break
continue
if
else
case
for
do
while
extern
2. Identifiers:
A valid identifier can have letters (both uppercase and lowercase letters), digits
and underscores.
3. Operators:
a. Unary Operators:
Those operators that require only a single operand to act upon are known
as unary operators. For Example increment and decrement operators.
Increment operators:
Pre (before) and post(after):
1. Pre increment and decrement:
a=5;
b=++a; (or) b= - -a;
printf(“%d %d”,a,b);
` 2. Post increment and decrement:
a=5;
b=a++; (or) b=a- -;
printf(“%d %d”,a,b);
b. Binary Operators:
*Acts on two operands*
Arithmetic- +, -, /, *
Relational- >, <, ==, >=, <=
Logical- Logical OR(||) and Logical AND (&&)
Assignment- ‘=’
Bitwise-
Bitwise And- &
Bitwise OR- |
BItwise X-OR- ^
Shift left- <<
Shift right- >>
Complement - ~
Ex:
1&1=1
1||1=1
9<<2
9- 00001001
Ans:
00100100
9>>2
Ans:
00000010
e. Special Characters
ex: \n=new line
\t= tab(4 spaces)
1. Local variables:
Accessibility: Within the block it is declared in
Default Value: Junk or garbage value
Lifetime: Til the block of statements terminate
Ex:
int x;
auto int x;
2. Static variables:
Accessibility: Can only get declared once, retains value, within block
Default value: 0
Lifetime: Till program ends
Ex:
void fn()
{
static int x;
x=x+1;
printf(“%d”,x);
}
int main()
{
fn();
fn();
fn();
}
3. Global variables
Accessibility: Throughout the program
Default value: 0
Lifetime: Till program ends
Ex:
int x;
void fn()
{
x=x+1;
printf(“%d”,x);
}
int main()
{
fn();
printf(“%d”,x);
}
void fn()
{
extern int x; // no memory space allocated
x=x+1;
printf(“%d”,x);
}
int x; // memory space is allocated
int main()
{
fn();
printf(“%d”,x);
}
Write a menu driven program for a simple calculator using a user defined function
Menu driven program- Provides a list of choices or options for the user, so
Output:
1. Addition
2. Subtraction
3. Multiplication
4. Division