Lecture#02 03
Lecture#02 03
CS-111
(4 CrH = 3 Theory 1 Lab)
Lecture No. 2&3
#include<iostream>
using namespace std;
int main( )
{
// write here your statement1;
// write here your statement2;
// write here your statement3;
// and so on …
return 0;
Today’s Lecture Agenda….
• Variables
• Operators
Programming in C++
• int a;
• float x;
• char abc;
• Storing character value in abc
variable
abc = ‘z’ ;
• This process is known as Variable
Declaration
Giving Names to Variables
• Following rules should follow for naming
the variables:
1. Upper case, lower case letters and
digits(0 to 9)
2. Underscore(_) can also be used
3. Name must start with a letter or
underscore
4. Keywords cannot be used as variable
name i.e. return,int, void etc.
Keywords
Variables
• Variables must be declared before
they are used in a program
Assigning Values
RAM
100
106
Displaying Values
RAM
100
101
int abc=10;
102
cout<<abc; 103
cout<<“abc=”<<abc; 104
abc105 10
106
Assigning Wrong type Values
RAM
100
abc 105 10
106
• Swapping of variables
• #include<iostream>
• #include<conio>
• int main(){
• int x,y,temp;
• cin>>x>>y;
• temp=x;
• x=y;
• y=temp;
• cout<<x<<endl<<y;
• return 0;
• }
Variables Types
Keyword Range Bytes of
Low High Memory
char -128 127 1
short -32,768 32768 2
int -2,147,483,648 2,147,483,647 4
long -2,147,483,648 2,147,483,647 4
float 3.4*10-38 3.4*1038 4
double 1.7*10-308 1.7*10308 8
long 3.4*10-4932 3.4*104932 10
double
Using Character
• #include<iostream>
• #include<conio>
• int main(){
• char x;
• x=‘A’;
• cout<<x;
• getch();
• return 0;
• }