CSCI 1110 - C++ Lecture Notes
Chapter 2 - C++ Syntax and Semantics,
and the Program Development Process


C++ Program Structure

Syntax and Semantics

Programming Style - Names

C++ Data Types

Assignment Statements and Expressions

Output


C++ Program Structure


Syntax and Semantics

 
Expression
Valid?
Reason
1
Valid
 
12345
Valid
 
0123
Not Valid
Must begin
NonzeroDigit
12.0
Not Valid
Contains character 
other than a digit
0
Not Valid
Must begin
NonzeroDigit
 
 

Programming Style - Names


C++ Data Types




Assignment Statements and Expressions

 
Operator
Meaning
+
Unary plus - no change
-
Unary minus - negation
+
Binary plus - addition
-
Binary minus - subtraction
*
Mulitplication
/
Division
%
Modulus - remainder from integer division
++
Unary increment - add one to variable
--
Unary decrement - subtract one from variable
 


Output

   
  Statement
What is printed
 cout << i;  2
 cout << "i = " << i; i = 2
 cout << "Sum = " << i + j; Sum = 8
 cout << "i = " << i  << endl 
      << "j = " << j << endl 
      << "sum = " << i + j << endl;
i = 2 
j = 6 
sum = 8




Updated January 27, 1999 by Tom Irby.
Copyright 1999 by Thomas C. Irby