Docsity

Program Elements Basics - Advanced Programming - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Program Elements Basics - Advanced Programming - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Advanced

Programming

Basics

Constants, Declarations, and Definitions

C++ Program Elements

C++ C

C++ Character Set

  • a -- z
  • A -- Z
  • 0 -- 9
  • ,. ; :?! ' " ( ) [ ]
  • { } < > | / \ ~ + - = # % & ^ *

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

Type

  • Fundamental -- int, char, float, double, long, short, signed, unsigned
  • Derived -- arrays, functions, pointers, references, classes, unions, structures, enumerations

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)

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

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

Acknowledgements

  • These slides were originally produced by Rajeev Raje, modified by Dale Roberts.