SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Variable declaration &
     initialization
• Declaration:
                                  int x;
                                 ↙ ↘
                     data type      identifier name
(for more than one variables separate them with commas)

• Initialization:
                                   x=9;
(value is stored )
• Declaration & initialization in one step:
             int x=9;
• = is an assignment operator
Int x,y=6,z=2;
x=y;             ////x=6
y=z;             ///y=2
z=x;            ///z=6
• Its associativity is right (it means right side of =(assignment
  operator )is evaluated first.)
Keywords/reserve words:
• Lower case letters
• E.g for,while,int,char,float
Variable:
• It can be modified. they are used to store constant values
• int→2 bytes        e.g 1,2,3 etc
• float → 4 bytes        e.g 1.1,2.3 etc
• char →1 byte         e.g A,S,D, 1 ,2,3, +,*,& etc
#include<iostream.h>
main()
{
cout<<“hello” ;
}
Operators
• Is anything that perform some action on some variable or constant
1.Unary operators
2.Binary operators
3.Arithmatic operators
1.Unary operators:
++, -- ,+ , -
They increment the value by 1.
(a)Unary minus operator:-
It is used to reverse the sign of a value.it makes a +ve value to –ve value and
     vice versa.e.g
int a, b;
a=87;
b=-a;
It has higher precedence over binary operator.
1.Increment operator:
(A)Prefix increment:
b=++a
a=a+1
b=a

(B)postfix increment:
b=a++
b=a
a=a+1
2.Decrement operator:
(A)Prefix decrement:
--y
b=--a
a=a-1
b=a
(B) postfix decrement:
b=a--
b=a
a=a-1

2.Binary operators:
• The operators that operate on two data items.
• E.g multiplication etc
3.Arithmatic operators: +, - ,* ,/ , %
• Remainder operator :modulus
Order of precedence
•   * , / ………………….left to right
•   + , - ………………….left to right
•   ( ) parenthesis ………………….left to right
•   Parenthesis within parenthesis(innermost first)
•   1+2+3-4+5
•   7+c*d/c
•   a/b/c
•   2+a/b*5
•   6+12/6*2-1
Type casting:
Conversion of one data type of numeric value to
  another
1.Implicit type casting
2.Explicit type casting
Arithmatic expressions:
2(a+b) →2*(a+b)
5/9(F-32) →5/9*(F-32)
Assignment operators: =
• Variable=expression
int a, b, c
a=200 ,b=100
c=a;
a=b;
b=c;
• Compound assignment:
  x=y=6;
Relational operator:
• Also called comparison operator
• After comparing two variables or expressions results into 0
  /1 or true /false
• ==
• !=
• <
• <=
• >
• >=
Logical operator:
1. and operator && (.)
2. or operator || (+)
3. not operator ! (-)
Conditional operator:
• It consists of “?” and “:”.
• Its syntax is
 {condition}?{exp1}:{exp2}
Where
Condition…..represents test condition
Exp1 & exp2….represents two expressions which
  may be arithmetic expression or constant value.
Sizeof operator:
void main()
{
int x;
cout<<sizeof(x);
}

2

Weitere ähnliche Inhalte

Was ist angesagt?

Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
Deepak Singh
 

Was ist angesagt? (20)

Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Arrays
ArraysArrays
Arrays
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Introduction to programming with dependent types in Scala
Introduction to programming with dependent types in ScalaIntroduction to programming with dependent types in Scala
Introduction to programming with dependent types in Scala
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional Programming
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Lab 13
Lab 13Lab 13
Lab 13
 
Arrays
ArraysArrays
Arrays
 
QuickCheck - Software Testing
QuickCheck - Software TestingQuickCheck - Software Testing
QuickCheck - Software Testing
 
Array in C
Array in CArray in C
Array in C
 
Monoids, monoids, monoids
Monoids, monoids, monoidsMonoids, monoids, monoids
Monoids, monoids, monoids
 
Multi dimensional array
Multi dimensional arrayMulti dimensional array
Multi dimensional array
 
Sigma type
Sigma typeSigma type
Sigma type
 
Templates
TemplatesTemplates
Templates
 
Principled Error Handling with FP
Principled Error Handling with FPPrincipled Error Handling with FP
Principled Error Handling with FP
 

Andere mochten auch (6)

Surface stresses..............................
Surface stresses..............................Surface stresses..............................
Surface stresses..............................
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
4 pump 03 reciprocating pump
4 pump 03 reciprocating pump4 pump 03 reciprocating pump
4 pump 03 reciprocating pump
 
reciprocating pumps
reciprocating pumps  reciprocating pumps
reciprocating pumps
 
Reciprocating pumps
Reciprocating pumpsReciprocating pumps
Reciprocating pumps
 
Reciprocating pump pdf
Reciprocating pump pdfReciprocating pump pdf
Reciprocating pump pdf
 

Ähnlich wie Lec2+lec3

Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
eShikshak
 

Ähnlich wie Lec2+lec3 (20)

2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
 
Operators
OperatorsOperators
Operators
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
What is c
What is cWhat is c
What is c
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
3.Loops_conditionals.pdf
3.Loops_conditionals.pdf3.Loops_conditionals.pdf
3.Loops_conditionals.pdf
 
C language basics
C language basicsC language basics
C language basics
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptx
 
B.sc CSIT 2nd semester C++ Unit2
B.sc CSIT  2nd semester C++ Unit2B.sc CSIT  2nd semester C++ Unit2
B.sc CSIT 2nd semester C++ Unit2
 
C++ process new
C++ process newC++ process new
C++ process new
 
Introduction to Python Language and Data Types
Introduction to Python Language and Data TypesIntroduction to Python Language and Data Types
Introduction to Python Language and Data Types
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
Lec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsLec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questions
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
Lec19
Lec19Lec19
Lec19
 

Mehr von Umer Warraich (20)

Lec03
Lec03Lec03
Lec03
 
Hydraulic actuator 2003
Hydraulic actuator 2003Hydraulic actuator 2003
Hydraulic actuator 2003
 
Hydraulic fluids(03336275386)
Hydraulic fluids(03336275386)Hydraulic fluids(03336275386)
Hydraulic fluids(03336275386)
 
Hydrauilc systems
Hydrauilc systemsHydrauilc systems
Hydrauilc systems
 
Soldering 2
Soldering 2Soldering 2
Soldering 2
 
Brazing
BrazingBrazing
Brazing
 
Lecture 11
Lecture 11Lecture 11
Lecture 11
 
Lecture 10 copy
Lecture  10   copyLecture  10   copy
Lecture 10 copy
 
Tig welding
Tig weldingTig welding
Tig welding
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Mig
MigMig
Mig
 
Mig
MigMig
Mig
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Mig
MigMig
Mig
 
7th lec welding
7th lec   welding7th lec   welding
7th lec welding
 
Sheet metal 3
Sheet metal 3Sheet metal 3
Sheet metal 3
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 

Kürzlich hochgeladen

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Kürzlich hochgeladen (20)

Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 

Lec2+lec3

  • 1. Variable declaration & initialization
  • 2. • Declaration: int x; ↙ ↘ data type identifier name (for more than one variables separate them with commas) • Initialization: x=9; (value is stored )
  • 3. • Declaration & initialization in one step: int x=9; • = is an assignment operator Int x,y=6,z=2; x=y; ////x=6 y=z; ///y=2 z=x; ///z=6
  • 4. • Its associativity is right (it means right side of =(assignment operator )is evaluated first.) Keywords/reserve words: • Lower case letters • E.g for,while,int,char,float Variable: • It can be modified. they are used to store constant values • int→2 bytes e.g 1,2,3 etc • float → 4 bytes e.g 1.1,2.3 etc • char →1 byte e.g A,S,D, 1 ,2,3, +,*,& etc
  • 6. Operators • Is anything that perform some action on some variable or constant 1.Unary operators 2.Binary operators 3.Arithmatic operators 1.Unary operators: ++, -- ,+ , - They increment the value by 1. (a)Unary minus operator:- It is used to reverse the sign of a value.it makes a +ve value to –ve value and vice versa.e.g int a, b; a=87; b=-a; It has higher precedence over binary operator.
  • 7. 1.Increment operator: (A)Prefix increment: b=++a a=a+1 b=a (B)postfix increment: b=a++ b=a a=a+1 2.Decrement operator: (A)Prefix decrement: --y b=--a a=a-1 b=a
  • 8. (B) postfix decrement: b=a-- b=a a=a-1 2.Binary operators: • The operators that operate on two data items. • E.g multiplication etc 3.Arithmatic operators: +, - ,* ,/ , % • Remainder operator :modulus
  • 9. Order of precedence • * , / ………………….left to right • + , - ………………….left to right • ( ) parenthesis ………………….left to right • Parenthesis within parenthesis(innermost first) • 1+2+3-4+5 • 7+c*d/c • a/b/c • 2+a/b*5 • 6+12/6*2-1
  • 10. Type casting: Conversion of one data type of numeric value to another 1.Implicit type casting 2.Explicit type casting Arithmatic expressions: 2(a+b) →2*(a+b) 5/9(F-32) →5/9*(F-32)
  • 11. Assignment operators: = • Variable=expression int a, b, c a=200 ,b=100 c=a; a=b; b=c;
  • 12. • Compound assignment: x=y=6; Relational operator: • Also called comparison operator • After comparing two variables or expressions results into 0 /1 or true /false • == • != • < • <= • > • >=
  • 13. Logical operator: 1. and operator && (.) 2. or operator || (+) 3. not operator ! (-)
  • 14. Conditional operator: • It consists of “?” and “:”. • Its syntax is {condition}?{exp1}:{exp2} Where Condition…..represents test condition Exp1 & exp2….represents two expressions which may be arithmetic expression or constant value.
  • 15. Sizeof operator: void main() { int x; cout<<sizeof(x); } 2