comments
use // for single line
use /*- */ for multiple lines
terminated
can't nest
enhance readability
document program
get into habit
document while fresh in mind
reap benefits of comments during debug phase
helps when reading through program
can help point to logic mistake
will not like backtracking to enter comments
Subtopic 6
prog1
// First program example
#import
import/include information from a system file
prog1
#import <Foundation/Foundation.h>
int main
program starts here
main
special name
indicateswhere program begins
int
reserved word that precedes main
value 'main' returns
prog1
int main (int argc, const char * argv[l
Misc
begin anywhere on the line
make programs easier to read
compiler doesn't care how many spaces exist
Upper/case lower case are distinct
[pool drain];
releases allocated memory pool
releases object associated with allocated memory pool
Xcode automatically inserts this line into Prog1
return 0;
terminate execution of main
send back or "return" status value of 0
0 means program ended normally
nonzero value means problem
Debug Console window
The Debugger has exited with status 0
status 0 means program worked
Statements
expression terminated with semicolon
enclosed in curly braces
part of the 'main' routine
specifies what 'main' routine performs
terminate all statements with semicolon - ;
variables
types
Integer
integral values
values without decimal
3, 5, -20, 0
int
Floating-point
decimals
2.4, 2.455, 27.0
real numbers
define
define/(declare?) before using
can declare anything to be a variable
definition tells compiler how program should use variable
compiler uses definition to generate instructions to store and retrieve values in/out of variable
NSLog
invoke/call routine NSLog
routine
function in ObjC library
Displays/Logs argument(s)
multiple arguments
first argument ("Format String")is always character string to be displayed
the next argument here is the variable, sum
this NSLog routine will display the string and then variable value
Percent character % is special character recognised by NSLog
the "i" following % specifies type of value to be displayed
with %i in character string, NSLog dusplays value of next argument
Displays/Logs phrases
Displays/Logs values of variables
Displays/Logs results of computations
Displays/Logs date/time routine executed (don't care about this)
prog1
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]
NSLog (@"Programming is fun!");
(@"Programming is fun!");
string of characters
pass/handle paramater/argument "Programming is fun !" to NSLog routine
@ sign makes this "constant NSString object"
adding lines of output
adding another call to NSLog routine
add picture for example
"Newline" character
two-character sequence
\n
\n tells system: go to a new line
characters printed after "n" go to new line
no spaces before/after
newline character example
character string
arguments
Ch.2 Exercise Questions
Untitled 2.rtf
Variables
Loading...