int main () ...
cout << "The square of 27 is";
| Character | Decimal | Hex | Binary |
|---|---|---|---|
| A | 65 | 41 | 0100 0001 |
| B | 66 | 42 | 0100 0010 |
| C | 67 | 43 | 0100 0011 |
| # | 35 | 23 | 0010 0011 |
| i | 105 | 69 | 0110 1001 |
| j | 106 | 6A | 0110 1010 |
"a string" "0 u 8 1 2?"
DataType Identifier; DataType Identifier, Identifier, ... ;
char Initial;
char response;
string first_name;
string middle_name, last_name;
int age;
int day, month, year;
char initial; // The player's first initial
char response; // responses to yes/no questions
string first_name; // the first name of the player
// Program 1, a program that does something
A simple, one sentence description of the program
// Programmer: Dan Bennett
Always include your name
// Class: CSCI 130 Section 3, Fall 2001
//
// This program will:
// - do this thing
// - do this other thing
// - do this last thing
A more detailed analysis of the program.
int age; // the person's age
char mi; // the person's middle initial
string first; // the person's first name
age = 18;
mi = 'A';
name ="Bob";
main () {
a = 7;
}
Will result in
foo.C:5: `a' undeclared (first use this function)
foo.C:5: (Each undeclared identifier is reported only once for each
From the compiler, assuming the program is called foo.C
const datatype identifier = value;
const float PI=3.14159; // the value of pi const char BLANK = ' '; // a blank character const string END_COMMAND = "exit"; // the command to stop processing
const float PI = 3.14159;
main () {
PI = 9.0394;
}
Will result in
foo.C: In function `int main ()':
foo.C:5: assignment of read-only variable `PI'
const float PI = 3.1415;
const char BLANK = ' ';
int main () {
char ch1, ch2;
float x,y,z;
x = 2;
y = 5;
z = x;
ch1 = 'a';
ch2 = BLANK;
x = PI;
return(0);
}
main:
ch1 ch2 x y z
---- ---- ---- ---- ---
a ' ' 2 5 2
3.1415