SlideShare a Scribd company logo
OPERATION AND EXPRESSION IN C++




                                  1
Basic Arithmetic Operation
• Arithmetic is performed with operators
   –   +   for addition
   –   -   for subtraction
   –   *   for multiplication
   –   /   for division

• Example: storing a product in the variable
           total_weight

  total_weight = one_weight * number_of_bars;
                                                2
Arithmetic Expression
• Arithmetic operators can be used with any
  numeric type
• An operand is a number or variable
  used by the operator
• Result of an operator depends on the types
  of operands
   – If both operands are int, the result is int
   – If one or both operands are double, the result is double



                                                                3
Arithmetic Expression (cont.)
• Division with at least one operator of type double
  produces the expected results.

              double divisor, dividend, quotient;
              divisor = 3;
                dividend = 5;
              quotient = dividend / divisor;

   – quotient = 1.6666…
   – Result is the same if either dividend or divisor is
     of type int

                                                           4
Arithmetic Expression (cont.)
• Be careful with the division operator!
   – int / int produces an integer result
      (true for variables or numeric constants)

             int dividend, divisor, quotient;
            dividend = 5;
            divisor = 3;
             quotient = dividend / divisor;

   – The value of quotient is 1, not 1.666…
   – Integer division does not round the result, the
     fractional part is discarded!

                                                       5
Arithmetic Expression (cont.)
• % operator gives the remainder from integer
  division
•       int dividend, divisor, remainder;
        dividend = 5;
        divisor = 3;
        remainder = dividend % divisor;

   The value of remainder is 2

                                                6
Arithmetic Expression (cont.)




                                7
Arithmetic Expression (cont.)




                                8
Arithmetic Expression (cont.)
• Use spacing to make expressions readable
   – Which is easier to read?

              x+y*z    or x + y * z

• Precedence rules for operators are the same as
  used in your algebra classes
• Use parentheses to alter the order of operations
   x + y * z ( y is multiplied by z first)
  (x + y) * z ( x and y are added first)

                                                     9
Arithmetic Expression (cont.)
• Some expressions occur so often that C++
  contains to shorthand operators for them
• All arithmetic operators can be used this way
   – += eg. count = count + 2; becomes
           count += 2;
   – *= eg. bonus = bonus * 2; becomes
           bonus *= 2;
   – /= eg. time = time / rush_factor; becomes
            time /= rush_factor;
   – %= eg. remainder = remainder % (cnt1+ cnt2); becomes
           remainder %= (cnt1 + cnt2);



                                                            10
Assignment Statement
• An assignment statement changes the value of a variable
   – total_weight = one_weight + number_of_bars;
       • total_weight is set to the sum one_weight + number_of_bars

   – Assignment statements end with a semi-colon

   – The single variable to be changed is always on the left
     of the assignment operator ‘=‘

   – On the right of the assignment operator can be
       • Constants -- age = 21;
       • Variables -- my_cost = your_cost;
       • Expressions -- circumference = diameter * 3.14159;



                                                                      11
Assignment Statement (cont.)
• The ‘=‘ operator in C++ is not an equal sign
   – The following statement cannot be true in algebra

      • number_of_bars = number_of_bars + 3;

   – In C++ it means the new value of number_of_bars
     is the previous value of number_of_bars plus 3




                                                         12
Assignment Statement (cont.) –
Initializing Variables
• Declaring a variable does not give it a value
   – Giving a variable its first value is initializing the variable
• Variables are initialized in assignment statements

              double mpg;        // declare the variable
              mpg = 26.3;       // initialize the variable
• Declaration and initialization can be combined
  using two methods
   – Method 1
                 double mpg = 26.3, area = 0.0 , volume;
   – Method 2
                 double mpg(26.3), area(0.0), volume;


                                                                      13
Relational Operation
• A Boolean Expression is an expression that is
  either true or false
   – Boolean expressions are evaluated using
     relational operations such as
      • = = , !=, < , >, <=, and >= which produce a boolean value
   – and boolean operations such as
      • &&, | |, and ! which also produce a boolean value
• Type bool allows declaration of variables that
  carry the value true or false


                                                                    14
Relational Operation (cont.)
• Boolean expressions are evaluated using
  values from the Truth Tables
• For example, if y is 8, the expression
             !( ( y < 3) | | ( y > 7) )
  is evaluated in the following sequence
              ! ( false | | true )
                    ! ( true )
                       false

                                            15
16
Mantic/Logic Operation – Order of
Precedence
• If parenthesis are omitted from boolean
  expressions, the default precedence of
  operations is:
  – Perform ! operations first
  – Perform relational operations such as < next
  – Perform && operations next
  – Perform | | operations last



                                                   17
Mantic/Logic Operation –Precedence
Rules
• Items in expressions are grouped by
  precedence
  rules for arithmetic and boolean operators
  – Operators with higher precedence are performed
    first
  – Binary operators with equal precedence are
    performed left to right
  – Unary operators of equal precedence are
    performed right to left

                                                 18
19
Precedence Rules - Example
• The expression
           (x+1) > 2 | | (x + 1) < -3

    is equivalent to
             ( (x + 1) > 2) | | ( ( x + 1) < -3)

    – Because > and < have higher precedence than | |

•     and is also equivalent to
             x+1>2||x+1<-3
                                                        20
Precedence Rules – Example (cont.)
• (x+1) > 2 | | (x + 1) < -3

• First apply the unary –
   – Next apply the +'s
   – Now apply the > and <
   – Finally do the | |




                                     21
Unary Operator
• Unary operators require only one operand
   – + in front of a number such as +5
   – - in front of a number such as -5
• ++ increment operator
   – Adds 1 to the value of a variable
                      x ++;
     is equivalent to x = x + 1;
• --   decrement operator
   – Subtracts 1 from the value of a variable
                      x --;
     is equivalent to    x = x – 1;

                                                22
Program Style
• A program written with attention to style
  – is easier to read
  – easier to correct
  – easier to change




                                              23
Program Style - Indenting
• Items considered a group should look like a
  group
   – Skip lines between logical groups of statements
   – Indent statements within statements
              if (x = = 0)
                 statement;
• Braces {} create groups
   – Indent within braces to make the group clear
   – Braces placed on separate lines are easier to locate


                                                            24
Program Style - Comments
• // is the symbol for a single line comment
   – Comments are explanatory notes for the programmer
   – All text on the line following // is ignored by the
     compiler
   – Example: //calculate regular wages
                  gross_pay = rate * hours;
• /* and */ enclose multiple line comments
   – Example: /* This is a comment that spans
                 multiple lines without a
                 comment symbol on the middle line
              */

                                                           25
Program Style - Constant
• Number constants have no mnemonic value
• Number constants used throughout a program
  are difficult to find and change when needed
• Constants
  – Allow us to name number constants so they have
    meaning
  – Allow us to change all occurrences simply by
    changing the value of the constant



                                                     26

More Related Content

What's hot (20)

PPTX
Operators and Expression
shubham_jangid
 
DOCX
C – operators and expressions
Chukka Nikhil Chakravarthy
 
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
Himanshu Kaushik
 
PPTX
Operators and Expressions in Java
Abhilash Nair
 
PPTX
Operators in C/C++
Shobi P P
 
PPT
Operators in C++
Sachin Sharma
 
PPT
operators and expressions in c++
sanya6900
 
PPT
C Prog. - Operators and Expressions
vinay arora
 
PPTX
Operators and Expressions
Munazza-Mah-Jabeen
 
PPT
Basic c operators
Anuja Lad
 
PPTX
Operator in c programming
Manoj Tyagi
 
ODP
Operators
jayesh30sikchi
 
PPTX
Expression and Operartor In C Programming
Kamal Acharya
 
PPTX
Operator.ppt
Darshan Patel
 
PPT
Expressions in c++
zeeshan turi
 
ODP
operators in c++
Kartik Fulara
 
PPTX
C OPERATOR
rricky98
 
PDF
Lecture03(c expressions & operators)
Dhaka University of Engineering & Technology(DUET)
 
PPTX
Basic c operators
dishti7
 
Operators and Expression
shubham_jangid
 
C – operators and expressions
Chukka Nikhil Chakravarthy
 
Lecture 2 C++ | Variable Scope, Operators in c++
Himanshu Kaushik
 
Operators and Expressions in Java
Abhilash Nair
 
Operators in C/C++
Shobi P P
 
Operators in C++
Sachin Sharma
 
operators and expressions in c++
sanya6900
 
C Prog. - Operators and Expressions
vinay arora
 
Operators and Expressions
Munazza-Mah-Jabeen
 
Basic c operators
Anuja Lad
 
Operator in c programming
Manoj Tyagi
 
Operators
jayesh30sikchi
 
Expression and Operartor In C Programming
Kamal Acharya
 
Operator.ppt
Darshan Patel
 
Expressions in c++
zeeshan turi
 
operators in c++
Kartik Fulara
 
C OPERATOR
rricky98
 
Lecture03(c expressions & operators)
Dhaka University of Engineering & Technology(DUET)
 
Basic c operators
dishti7
 

Viewers also liked (15)

PPTX
03. operators and-expressions
Stoian Kirov
 
PPT
Lecture 3
Mohammed Saleh
 
PPTX
Matrices
marcelafernandagarzon
 
PPTX
computer networks
Santosh Jhansi
 
PPTX
Operator Precedence and Associativity
Nicole Ynne Estabillo
 
PPTX
Operators
moniammu
 
PDF
Operator precedence
Akshaya Arunan
 
PPT
Mesics lecture 4 c operators and experssions
eShikshak
 
PPTX
C++ Project: Point of Sales System for an Audio and Video Shop
projectlearner
 
PPT
Expectations (Algebra 1)
rfant
 
PDF
multimedia authorizing tools
Santosh Jhansi
 
PPT
Philosophy of early childhood education 3
Online
 
PPTX
algebraic expression class VIII
Himani Priya
 
PPT
Multimedia authoring tools
Online
 
PPTX
Slideshare ppt
Mandy Suzanne
 
03. operators and-expressions
Stoian Kirov
 
Lecture 3
Mohammed Saleh
 
computer networks
Santosh Jhansi
 
Operator Precedence and Associativity
Nicole Ynne Estabillo
 
Operators
moniammu
 
Operator precedence
Akshaya Arunan
 
Mesics lecture 4 c operators and experssions
eShikshak
 
C++ Project: Point of Sales System for an Audio and Video Shop
projectlearner
 
Expectations (Algebra 1)
rfant
 
multimedia authorizing tools
Santosh Jhansi
 
Philosophy of early childhood education 3
Online
 
algebraic expression class VIII
Himani Priya
 
Multimedia authoring tools
Online
 
Slideshare ppt
Mandy Suzanne
 
Ad

Similar to Operation and expression in c++ (20)

PPT
FP 201 Unit 2 - Part 3
rohassanie
 
PDF
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
PPT
Report Group 4 Constants and Variables
Genard Briane Ancero
 
PPT
Report Group 4 Constants and Variables(TLE)
Genard Briane Ancero
 
PPS
C programming session 02
Dushmanta Nath
 
PDF
Arithmetic instructions
Learn By Watch
 
PPT
operators and arithmatic expression in C Language
ParamesswariNataraja
 
PDF
+2 Computer Science - Volume II Notes
Andrew Raj
 
PPSX
Chapter 07
wantedwahab
 
PPT
Project in TLE
PGT_13
 
PDF
C++ revision tour
Swarup Kumar Boro
 
PDF
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
Muhammad Hammad Waseem
 
PPS
02 iec t1_s1_oo_ps_session_02
Niit Care
 
PPTX
c programming2.pptx
YuvarajuCherukuri
 
PDF
Lamborghini Veneno Allegheri #2004@f**ck
seidounsemel
 
PDF
ICP - Lecture 5
Hassaan Rahman
 
PPT
Token and operators
Samsil Arefin
 
PDF
Chapter 13.1.2
patcha535
 
PPT
Operators in C
yarkhosh
 
PPTX
Variables, Data Types, Operator & Expression in c in detail
gourav kottawar
 
FP 201 Unit 2 - Part 3
rohassanie
 
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Report Group 4 Constants and Variables
Genard Briane Ancero
 
Report Group 4 Constants and Variables(TLE)
Genard Briane Ancero
 
C programming session 02
Dushmanta Nath
 
Arithmetic instructions
Learn By Watch
 
operators and arithmatic expression in C Language
ParamesswariNataraja
 
+2 Computer Science - Volume II Notes
Andrew Raj
 
Chapter 07
wantedwahab
 
Project in TLE
PGT_13
 
C++ revision tour
Swarup Kumar Boro
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
Muhammad Hammad Waseem
 
02 iec t1_s1_oo_ps_session_02
Niit Care
 
c programming2.pptx
YuvarajuCherukuri
 
Lamborghini Veneno Allegheri #2004@f**ck
seidounsemel
 
ICP - Lecture 5
Hassaan Rahman
 
Token and operators
Samsil Arefin
 
Chapter 13.1.2
patcha535
 
Operators in C
yarkhosh
 
Variables, Data Types, Operator & Expression in c in detail
gourav kottawar
 
Ad

More from Online (20)

PPT
Philosophy of early childhood education 2
Online
 
PPT
Philosophy of early childhood education 1
Online
 
PPT
Philosophy of early childhood education 4
Online
 
PPT
Functions
Online
 
PPT
Formatted input and output
Online
 
PPT
Control structures selection
Online
 
PPT
Control structures repetition
Online
 
PPT
Introduction to problem solving in c++
Online
 
PPT
Optical transmission technique
Online
 
PPT
Multi protocol label switching (mpls)
Online
 
PPT
Lan technologies
Online
 
PPT
Introduction to internet technology
Online
 
PPT
Internet standard routing protocols
Online
 
PPT
Internet protocol
Online
 
PPT
Application protocols
Online
 
PPT
Addressing
Online
 
PPT
Transport protocols
Online
 
PPT
Leadership
Online
 
PPT
Introduction to management
Online
 
PPT
Motivation
Online
 
Philosophy of early childhood education 2
Online
 
Philosophy of early childhood education 1
Online
 
Philosophy of early childhood education 4
Online
 
Functions
Online
 
Formatted input and output
Online
 
Control structures selection
Online
 
Control structures repetition
Online
 
Introduction to problem solving in c++
Online
 
Optical transmission technique
Online
 
Multi protocol label switching (mpls)
Online
 
Lan technologies
Online
 
Introduction to internet technology
Online
 
Internet standard routing protocols
Online
 
Internet protocol
Online
 
Application protocols
Online
 
Addressing
Online
 
Transport protocols
Online
 
Leadership
Online
 
Introduction to management
Online
 
Motivation
Online
 

Recently uploaded (20)

PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Quarter1-English3-W4-Identifying Elements of the Story
FLORRACHELSANTOS
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Quarter1-English3-W4-Identifying Elements of the Story
FLORRACHELSANTOS
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Dimensions of Societal Planning in Commonism
StefanMz
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 

Operation and expression in c++

  • 2. Basic Arithmetic Operation • Arithmetic is performed with operators – + for addition – - for subtraction – * for multiplication – / for division • Example: storing a product in the variable total_weight total_weight = one_weight * number_of_bars; 2
  • 3. Arithmetic Expression • Arithmetic operators can be used with any numeric type • An operand is a number or variable used by the operator • Result of an operator depends on the types of operands – If both operands are int, the result is int – If one or both operands are double, the result is double 3
  • 4. Arithmetic Expression (cont.) • Division with at least one operator of type double produces the expected results. double divisor, dividend, quotient; divisor = 3; dividend = 5; quotient = dividend / divisor; – quotient = 1.6666… – Result is the same if either dividend or divisor is of type int 4
  • 5. Arithmetic Expression (cont.) • Be careful with the division operator! – int / int produces an integer result (true for variables or numeric constants) int dividend, divisor, quotient; dividend = 5; divisor = 3; quotient = dividend / divisor; – The value of quotient is 1, not 1.666… – Integer division does not round the result, the fractional part is discarded! 5
  • 6. Arithmetic Expression (cont.) • % operator gives the remainder from integer division • int dividend, divisor, remainder; dividend = 5; divisor = 3; remainder = dividend % divisor; The value of remainder is 2 6
  • 9. Arithmetic Expression (cont.) • Use spacing to make expressions readable – Which is easier to read? x+y*z or x + y * z • Precedence rules for operators are the same as used in your algebra classes • Use parentheses to alter the order of operations x + y * z ( y is multiplied by z first) (x + y) * z ( x and y are added first) 9
  • 10. Arithmetic Expression (cont.) • Some expressions occur so often that C++ contains to shorthand operators for them • All arithmetic operators can be used this way – += eg. count = count + 2; becomes count += 2; – *= eg. bonus = bonus * 2; becomes bonus *= 2; – /= eg. time = time / rush_factor; becomes time /= rush_factor; – %= eg. remainder = remainder % (cnt1+ cnt2); becomes remainder %= (cnt1 + cnt2); 10
  • 11. Assignment Statement • An assignment statement changes the value of a variable – total_weight = one_weight + number_of_bars; • total_weight is set to the sum one_weight + number_of_bars – Assignment statements end with a semi-colon – The single variable to be changed is always on the left of the assignment operator ‘=‘ – On the right of the assignment operator can be • Constants -- age = 21; • Variables -- my_cost = your_cost; • Expressions -- circumference = diameter * 3.14159; 11
  • 12. Assignment Statement (cont.) • The ‘=‘ operator in C++ is not an equal sign – The following statement cannot be true in algebra • number_of_bars = number_of_bars + 3; – In C++ it means the new value of number_of_bars is the previous value of number_of_bars plus 3 12
  • 13. Assignment Statement (cont.) – Initializing Variables • Declaring a variable does not give it a value – Giving a variable its first value is initializing the variable • Variables are initialized in assignment statements double mpg; // declare the variable mpg = 26.3; // initialize the variable • Declaration and initialization can be combined using two methods – Method 1 double mpg = 26.3, area = 0.0 , volume; – Method 2 double mpg(26.3), area(0.0), volume; 13
  • 14. Relational Operation • A Boolean Expression is an expression that is either true or false – Boolean expressions are evaluated using relational operations such as • = = , !=, < , >, <=, and >= which produce a boolean value – and boolean operations such as • &&, | |, and ! which also produce a boolean value • Type bool allows declaration of variables that carry the value true or false 14
  • 15. Relational Operation (cont.) • Boolean expressions are evaluated using values from the Truth Tables • For example, if y is 8, the expression !( ( y < 3) | | ( y > 7) ) is evaluated in the following sequence ! ( false | | true ) ! ( true ) false 15
  • 16. 16
  • 17. Mantic/Logic Operation – Order of Precedence • If parenthesis are omitted from boolean expressions, the default precedence of operations is: – Perform ! operations first – Perform relational operations such as < next – Perform && operations next – Perform | | operations last 17
  • 18. Mantic/Logic Operation –Precedence Rules • Items in expressions are grouped by precedence rules for arithmetic and boolean operators – Operators with higher precedence are performed first – Binary operators with equal precedence are performed left to right – Unary operators of equal precedence are performed right to left 18
  • 19. 19
  • 20. Precedence Rules - Example • The expression (x+1) > 2 | | (x + 1) < -3 is equivalent to ( (x + 1) > 2) | | ( ( x + 1) < -3) – Because > and < have higher precedence than | | • and is also equivalent to x+1>2||x+1<-3 20
  • 21. Precedence Rules – Example (cont.) • (x+1) > 2 | | (x + 1) < -3 • First apply the unary – – Next apply the +'s – Now apply the > and < – Finally do the | | 21
  • 22. Unary Operator • Unary operators require only one operand – + in front of a number such as +5 – - in front of a number such as -5 • ++ increment operator – Adds 1 to the value of a variable x ++; is equivalent to x = x + 1; • -- decrement operator – Subtracts 1 from the value of a variable x --; is equivalent to x = x – 1; 22
  • 23. Program Style • A program written with attention to style – is easier to read – easier to correct – easier to change 23
  • 24. Program Style - Indenting • Items considered a group should look like a group – Skip lines between logical groups of statements – Indent statements within statements if (x = = 0) statement; • Braces {} create groups – Indent within braces to make the group clear – Braces placed on separate lines are easier to locate 24
  • 25. Program Style - Comments • // is the symbol for a single line comment – Comments are explanatory notes for the programmer – All text on the line following // is ignored by the compiler – Example: //calculate regular wages gross_pay = rate * hours; • /* and */ enclose multiple line comments – Example: /* This is a comment that spans multiple lines without a comment symbol on the middle line */ 25
  • 26. Program Style - Constant • Number constants have no mnemonic value • Number constants used throughout a program are difficult to find and change when needed • Constants – Allow us to name number constants so they have meaning – Allow us to change all occurrences simply by changing the value of the constant 26