130 likes | 211 Views
Constants, Declarations, and Definitions. Advanced Programming Basics. C++ Program Elements. C++ C. Lexical Tokens. Character Set Keywords Identifiers Constants Literal Strings Operators Punctuators Special Characters. C++ Character Set. a -- z A -- Z 0 -- 9
E N D
Constants, Declarations, and Definitions Advanced ProgrammingBasics
C++ Program Elements C++ C CSCI 240: Computing II
Lexical Tokens • Character Set • Keywords • Identifiers • Constants • Literal Strings • Operators • Punctuators • Special Characters CSCI 240: Computing II
C++ Character Set • a -- z • A -- Z • 0 -- 9 • , . ; : ? ! ' " ( ) [ ] • { } <>| / \ ~ + - = # % & ^ * CSCI 240: Computing II
Identifiers • Name to denote Object, Function, Tag, typedef, Label or Macro • First character is alpha, followed by any number of alpha, numerals or an underscore. (Leading _ reserved for internal use.) • Case sensitive • Reserved words cannot be used CSCI 240: Computing II
Attributes of Identifiers • Type • Visibility (Scope) • Uniqueness (Linkage) • Permanence (Duration) • Storage Class • Qualifier (Modifiability) CSCI 240: Computing II
Type • Fundamental -- int, char, float, double, long, short, signed, unsigned • Derived -- arrays, functions, pointers, references, classes, unions, structures, enumerations CSCI 240: Computing II
Scope • An Identifier can be Used within its Scope • File Scope – Global (C) • Class Scope -- Member of a Class (C++) • Function -- Labels (C) • Local -- Inside a Block (C) CSCI 240: Computing II
Linkages • Bindings between identifiers • External • “extern” – not local to a file (means not allocated here) • Internal • local to a file – e.g., “static” • No linkage • e.g., classes, enumerations – must be unique across all files (#ifndef, #define, #endif used to control this) CSCI 240: Computing II
Storage Duration • Static • Storage assigned once before the program startup, initialized only once, exists throughout the program • Automatic • Storage assigned in a block, their status is completely undefined after the completion of the block where they were defined CSCI 240: Computing II
Storage Class • Auto – default – automatic variables • Extern – external objects • Register – internal auto variables stored in hardware registers – fast access (advisory) • Static – in a block, a file or a class CSCI 240: Computing II
Qualifiers • No qualifier – default – alteration allowed • Const – no alteration is allowed CSCI 240: Computing II
Acknowledgements • These slides were originally produced by Rajeev Raje, modified by Dale Roberts. CSCI 240: Computing II