Professional Documents
Culture Documents
Cse 191 - Computer Programming
Cse 191 - Computer Programming
Najia Manjur
Lecturer
Department of Computer Science & Engineering (CSE)
Military Institute of Science & Technology (MIST)
Mirpur, Dhaka – 1216, Bangladesh
Scope of variable
#include<stdio.h>
void sum()
{
Same name of the variables.
int x; But different function makes
the scope of the variable
} different.
So, No Conflict!
void main()
Local Variable :
{ • Visible and meaningful only
inside the function in which
int x; they are declared.
• Not known to other functions.
}
2
Scope of variable
#include<stdio.h>
void main()
{
int a = 100;
if(a > 100)
{
int b = 1; // b is known inside this scope
}
//b is not known here
}
// a is not known here
3
Scope of variable
#include<stdio.h>
void main()
{
int x = 15;
if(x == 15)
{ Hides the outer
int x; variable x
x = 99;
printf(“%d”, x); //So, here x = 99
}
//Here x = 15
printf(“%d”, x);
}
4
Scope of variable
#include<stdio.h>
int b = 1; global variable
void main()
{
int a = 100;
if(a > 100)
{
b = 2; // b is known anywhere in the program.
}
//b is known here
}
// b is known here
5
Symbolic Constant
Structure:
#define name value
6
Symbolic Constant
Variable declaration
int a = 10
Symbolic Constant
#define a 10
7
Symbolic Constant
Example:
8
Regular ASCII Characters (0-127)
Regular ASCII Chart(codes 0-127)
9
Arithmetic Operators
Ari
10
Relational Operators
11
Logical Operators
12
Bitwise Operators
13
Assignment Operators
Operator Name Example Meaning
= Assignment Var = 7; Var 7
++ Increment and var++; var = var + 1;
Assignment
-- Decrement and Var--; var = var – 1;
Assignment
+= Add and assign var += 7; var = var + 7;
–= Subtract and assign var –= var1; var = var – var1;
*= Multiply and assign var *= 7; var = var * 7;
/= Divide and assign var /= var1; var = var / var1;
%= Take modulus and assign var %= var1; var = var % var1;
|= bitwise OR and assign var |= var1; var = var | var1;
&= bitwise AND and assign var &= var1; var = var & var1;
^= bitwise XOR and assign var ^= var1; var = var ^ var1;
<<= Left shift and assign var <<= 2; var = var << 2;
>>= Right shift and assign var >>= var1; var = var >> var1;
14
Ternary Operator
?:
condition ? true result : false result;
15
Reference
Text Books
Schaum’s Outlines Programming with C (3rd Edition) – Byron Gottfried
Chapter – 2
Chapter – 3 (3.1, 3.2, 3.3, 3.4, 3.5)
All examples (Section 3.2, 3.3,
3.4, 3.5)
End of Slides