Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The Basics of a C++ Program Function: Collection of statements; when executed, accomplish something. May be predefined or standard
Syntax: rules that specify which statements are legal Programming language: a set of rules, symbols, and special words Semantic rule: meaning of instruction Comments Comments are for the reader, not the compiler Two types Single line (//) Multiple line (/*)
Special Symbols + - * / . ; ? , < = ! = == > = Reserved Words (Keywords) Reserved words, keywords or word symbols
Identifiers Consists of letters, digits, and the underscore character Must begin with a letter or underscore C++ is case sensitive Two predefined identifiers are cout and cin Unlike reserved words, predefined identifiers may be redefined, but it is not a good idea
Legal Identifiers in C++: first conversion payRate there can be no space no symbols cannot begin w/ a number
Whitespaces every C++ Program contains whitespaces include blanks, tabs, and newline characters
used to separate symbols, reserved words, and identifiers proper utilization of whitespaces is important can be used to make the program readable
Data Types Data type: set of values together with a set of operations Simple Data Type integral: integers floating-point: decimal enumeration type: user defined
Integral Data types: char, short, int, long, bool unsigned char, unsigned short, unsigned int, unsigned long
bool true and false different compiler s may allow different ranges of values
float: represents any real number (4bytes) 7SF double: (8byes) 15SF
Arithmetic Operators and Operator Precedence + -/*% Can be unary or binary All operations inside the () are evaluated first *,/, % same level +, - same level Left to Right (associativity)
Expressions If all operands are integers (integral expression) If all operands are floating point (floating-point expression) Mixed expressions (combination)
Evaluation Rules: If same types the result would be the same When different int is changed to double Evaluated according to precedence
Type Conversion (Casting) Cast operator - static_cast <datatype> ( ) implicit type coercion - automatic
string Type programmer-defined type supplied in ANSI/ISO Standard C++ library sequence of zero or more characters enclosed in double quotation marks null: a string w/ no characters each character has a relative position in string