• Like
Lec2+lec3
Upcoming SlideShare
Loading in...5
×

Lec2+lec3

  • 160 views
Uploaded on

 

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
160
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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 operatorInt x,y=6,z=2;x=y; ////x=6y=z; ///y=2z=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,floatVariable:• 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
  • 5. #include<iostream.h>main(){cout<<“hello” ;}
  • 6. Operators• Is anything that perform some action on some variable or constant1.Unary operators2.Binary operators3.Arithmatic operators1.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.gint a, b;a=87;b=-a;It has higher precedence over binary operator.
  • 7. 1.Increment operator:(A)Prefix increment:b=++aa=a+1b=a(B)postfix increment:b=a++b=aa=a+12.Decrement operator:(A)Prefix decrement:--yb=--aa=a-1b=a
  • 8. (B) postfix decrement:b=a--b=aa=a-12.Binary operators:• The operators that operate on two data items.• E.g multiplication etc3.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 another1.Implicit type casting2.Explicit type castingArithmatic expressions:2(a+b) →2*(a+b)5/9(F-32) →5/9*(F-32)
  • 11. Assignment operators: =• Variable=expressionint a, b, ca=200 ,b=100c=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}WhereCondition…..represents test conditionExp1 & exp2….represents two expressions which may be arithmetic expression or constant value.
  • 15. Sizeof operator:void main(){int x;cout<<sizeof(x);}2