S1 2 Handout
S1 2 Handout
)
Section 1.2
Basic Language Features ● Characteristics
➢ selective
➢ each box is in a specific location on the shelf
example: switch
● Variables are like those boxes
➢ iterative ➢ they come in different sizes, based on data type
example: for, while, dowhile examples: int, double, char
➢ they have a name
➢ jump ➢ they contain something, called a value
example: break, continue
➢ they have a location in memory
represented as a memory address where the value is stored
Control and Data Structures (cont.) Variables and Data Types (cont.)
● Data structures ● Characteristics of variables:
● cin
➢ istream object used for standard input
● Member functions:
➢ take data in, do something, return result ➢ they are treated as local variables inside a function
two ways to return results: return value or using parameters
● Parameter modifiability:
➢ are single-purpose
have a single goal, do one thing only ➢ pass-by-value
parameter value is copied from the calling function
➢ encapsulate (hide) their functionality function works on local copy
other programmers know what function does, not how it does it
➢ pass-by-reference
➢ should be reusable parameter is memory address of variable declared in calling function
in the same program, or in other programs allow variables in calling function to be modified
in C++, this can be done using pointers or references
References (cont.)
● What is a reference not?
➢ a reference is not a variable! it does not occupy memory
➢ it must be assigned a value on declaration
➢ its value can never change
● So what is it?
➢ a binding, or an alias, for an existing variable
➢ declaring and initializing a reference creates a bond between:
the reference name
an existing variable
➢ the bond is unbreakable
➢ most common use is passing parameters by reference