< Back
Page 5 of 5
This chapter is from the book
Exercises
- Type in and run the five programs presented in this chapter. Compare the output produced by each program with the output presented after each program.
- Write a program that displays the following text:
In Objective-C, lowercase letters are significant. main is where program execution begins. Open and closed braces enclose program statements in a routine. All program statements must be terminated by a semicolon.
- What output would you expect from the following program?
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { int i; i = 1; NSLog (@"Testing..."); NSLog (@"....%i", i); NSLog (@"...%i", i + 1); NSLog (@"..%i", i + 2); } return 0; }
- Write a program that subtracts the value 15 from 87 and displays the result, together with an appropriate message.
- Identify the syntactic errors in the following program. Then type in and run the corrected program to make sure you have identified all the mistakes:
#import <Foundation/Foundation.h> int main (int argc, const char *argv[]); ( @autoreleasepool { INT sum; /* COMPUTE RESULT // sum = 25 + 37 - 19 / DISPLAY RESULTS / NSLog (@'The answer is %i' sum); } return 0; }
- What output would you expect from the following program?
#import <Foundation/Foundation.h> int main (int argc, const char *argv[]) { @autoreleasepool { int answer, result; answer = 100; result = answer - 10; NSLog (@"The result is %i\ n", result + 5); } return 0; }
< Back
Page 5 of 5