Download presentation
Presentation is loading. Please wait.
1
Advanced Programming Basics
Constants, Declarations, and Definitions Advanced Programming Basics
2
C++ Program Elements C++ C 11/19/2018 CSCI 240: Computing II
3
Lexical Tokens Character Set Keywords Identifiers Constants
Literal Strings Operators Punctuators Special Characters 11/19/2018 CSCI 240: Computing II
4
C++ Character Set a -- z A -- Z 0 -- 9 , . ; : ? ! ' " ( ) [ ]
{ } < > | / \ ~ + - = # % & ^ * 11/19/2018 CSCI 240: Computing II
5
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 11/19/2018 CSCI 240: Computing II
6
Attributes of Identifiers
Type Visibility (Scope) Uniqueness (Linkage) Permanence (Duration) Storage Class Qualifier (Modifiability) 11/19/2018 CSCI 240: Computing II
7
Type Fundamental -- int, char, float, double, long, short, signed, unsigned Derived -- arrays, functions, pointers, references, classes, unions, structures, enumerations 11/19/2018 CSCI 240: Computing II
8
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) 11/19/2018 CSCI 240: Computing II
9
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) 11/19/2018 CSCI 240: Computing II
10
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 11/19/2018 CSCI 240: Computing II
11
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 11/19/2018 CSCI 240: Computing II
12
Qualifiers No qualifier – default – alteration allowed
Const – no alteration is allowed 11/19/2018 CSCI 240: Computing II
13
Acknowledgements These slides were originally produced by Rajeev Raje, modified by Dale Roberts. 11/19/2018 CSCI 240: Computing II
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.