2 + 3. Anatomy of a program Flashcards
(36 cards)
when we run a program we are running
a) an object file
b) a machine language file
-computers understand machine language, and object files are in machine language
object file
file containing object code
use of xcode
to type in + edit your program files
terminal utility
gives UNIX interface, used to enter UNIX commands to iMac
terminal commands
cd: change directory
ls: show programs in folder
make: compiles program
when compiling program
don’t type .cpp, just write the file name
troubleshooting: ‘program’ is up to date
probably forgot to save edited program
troubleshooting: no rule to make target ‘program’
mistyped filename or file not in current directory
troubleshooting: use of undeclared identifier
syntax error, didnt declare a variable
Use of // or /* */
a comment (ignored)
include
allows program to use built-in facilities for input and output (IO)
int main () {}
a function that returns an integer (int), function is called main
return 0
main returns the integer 0
{ }
used to define functions/processes
variables
places which store values
valid variable names
start w/ letter or underscore
rest is letters, digits, or underscore
notes on using variables
- case sensitive eg. rate vs Rate vs RATE
- don’t use reserved keywords eg. int, for, while
data type
what kind of thing you want to store in a variable
Data types
- int
- double
- bool
- char
- string
int
integers
double
decimal number
bool
true/false values
char
used to hold a letter/digit or other symbol eg. “a” “&” or “ “ (a space)
string
for sequences of characters eg “hello”