Pascal |
C++ |
|
order of operation | Highest
not second (multiplicative operators)
third (additive operators)
Lowest (relational operators)
|
Highest (monadic)
++, --, &, ~, (type), !, -, +, sizeof Multiplicative *, /, % Additive +, - bitwise shift <<, >> relational <, <=, >, >= relational ==, != bitwise & bitwise ^ bitwise | logical && logical || ternary .?: -- this is a single operator assignment (right to left) =, +=, -+, *=, /=, %=, >>=, <<=, &=, |=, ^= Lowest (comma) , -- the comma is an operator |
variable declaration | before the subprogram body
var x, y: integer; z: array [0..25] of real; w: string; within the subprogram body
|
within the subprogram body or
any compound statement int x = 5;
|
procedure header | procedure Alpha(var X: integer;
const Y: real; var Z: array of integer); |
void Alpha(int *X, float Y, Z[]); |
function header | function Swap(const X, Y: integer): boolean; | int Swap(int X, Y); |
subprogram body
compound statement |
begin
sequence of statement end |
{
sequence of statements } |
Assignment Statement | variable := expression | variable = expression; // semicolon part of statement |
If Statement | if expression then statement [ else statement ] | if ( expression ) statement [ elsestatement ] |
pretest loop | while expression do statement | while ( expression ) statement |
posttest loop | repeat sequence of statements until expression | do statement while expression ; |
for loop | for var := initial ( to | downto ) final do statement | for (exp1 ; exp2 ; exp3) statement |
case | case expression of
const1: statement; const2: statement; const3, const4: statement; else statement end |
switch ( expression )
{ const1: one or more statements; break; const2: one or more statements; break; const3: const4: one or more statements; break; default: one or more statements; } |
declare a file variable | var FileVar: TextFile; | fstream FileVar; |
Open file for output | var FileVar: TextFile;
AssignFile(FileVar, filename);
|
#include <fstream.h>
fstream FileVar;
|
Open file for input | var FileVar: TextFile;
AssignFile(FileVar, filename);
|
#include <fstream.h>
fstream FileVar;
|
Close file | CloseFile(FileVar); | FileVar.close(); |
read from a file | read(FileVar, dataValue);
readln(FileVar, dataValue); |
FileVar >> dataValue;
FileVar >> dataValue >> ???; |
write to a file | write(FileVar, value1, value2);
writeln(FileVar, value1, value2); |
FileVar << value1 << value2;
FileVar << value1 << value2 << endl; |