# OLYMPIA COLLEGE

Document Sample

OLYMPIA COLLEGE

ASSIGNMENT
Introduction to Programming
IT 202(08)
Olympia College                          Assignment      Diploma in Information Technology

QUESTIONS

Guidelines to students:

1. The word count should be limited to 1,500 words for each question.
2. Use Font Times New Roman 12, and type in double line spacing.
3. Both questions should be submitted as one assignment and bound in one
booklet with separators/ sheets for each of the questions.
4. Cut and paste work, plagiarism and undeclared sources will result in an
automatic failure.
5. All assignments or projects will have a compulsory presentation requirement
which carries 10%. Communication skills, visual aids and personal grooming
are the criteria for obtaining the 10%.

Answer both questions:                                    (2Q * 15% = 30%)
(Presentation = 10%)
Question 1

Given the following declarations:

int m = 1, n = 2, i = 0, j = 5;

Give the value of each expression, and state the values of the variables after the
expression is evaluated. Consider each one separately; that is, assume each one appears
immediately after the given declarations.

1.   m =   n++ + 3
2.   m =   ++n
3.   m =   (n = 5)   + 2
4.   i--   && (4 *   ++m <= 4 || ++n - 2)
5.   --i   || (4 *   ++m <= 4 && n++ - 2)
6.   --i   && (4 *   ++m <= 4 && n++ - 2)
7.   j >   n > m

Question 2

What is printed by each piece of code?
1.
2.              char fred[50];
3.
4.              strcpy(fred, "Today");
5.              if (fred == "Today")
6.                      printf("Of course!\n");
7.              else
8.                      printf("Today is not Today on planet C.\n");

________________________________________________________________________
Intro to Programming                                                   Page 2 of 3
Olympia College                      Assignment       Diploma in Information Technology

9.
10.
11.               char fred1[] = "barney", fred2[20] = "barney", *fred3 =
"barney";
12.
13.               printf("%d %d %d %d %d %d\n",
14.                       strlen(fred1), strlen(fred2), strlen(fred3),
15.                       sizeof fred1, sizeof fred2, sizeof fred3);
16.
17.
18.               char sue[] = "susan", *p;
19.
20.               for(p = sue; *p++; )
21.                       printf("%s", p);
22.               printf("\n");
23.
24.
25.               char bill[50] = "william";
26.
27.               strcpy(bill + 3, "ey coyote");
28.               printf("%s\n", bill);
29.
30.
31.               char *sharon = "sharon";
32.
33.               while(*++sharon) printf("%c", sharon[-1]);
34.               printf("\n");
35.

________________________________________________________________________
Intro to Programming                                                Page 3 of 3

DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 118 posted: 10/19/2010 language: English pages: 3
How are you planning on using Docstoc?