C2 Assignment 1A
C2 Assignment 1A
1 7. What is the value and data type of the expression: (char)25 < (char)100
2 (Note 2.10; Note 3.1)
3 A. 1; type char
4 B. 1; type int
5 C. 75; type char
6 D. 0; type char
7 E. none of the above
8
9 8. Predict what gets printed:
10 (Note 2.14)
11 const int i;
12 for (i = 0; i < 5; ++i)
13 cout << i << ' ';
14 A. 0 1 2 3 4
15 B. 0 1 2 3 4 5
16 C. 1 2 3 4 5
17 D. It won't compile.
18 E. Output is implementation dependent.
19
20 9. Predict what gets printed by: printf("Goodbye") && printf(" Cruel") || printf(" World")
21 (Note 3.2)
22 A. Goodbye
23 B. Goodbye Cruel
24 C. Goodbye Cruel World
25 D. Goodbye World
26 E. Output is implementation dependent.
27
28 10. For int x = 1; predict the value in x after: x = ++x
29 (Note 3.4)
30 A. 1
31 B. 2
32 C. 3
33 D. undefined
34 E. implementation dependent
35
36 11. Predict final value of i:
37 (Note 3.10)
38 for (int i = 0; i < 5; ++i)
39 break;
40 A. 0
41 B. 1
42 C. 2
43 D. 3
44 E. none of the above
45
46 12. Predict the value in x after: auto int x = (4, printf("Hello"), sqrt(64.), printf("World"));
47 (Note 3.11)
48 A. 4
49 B. 5
50 C. 6
51 D. 8
52 E. implementation dependent
53
1 18. In C, which statement is true concerning a major problem with the following?
2 (Note 5.4)
3 long double fx(void)
4 {
5 double answer = sum(1.1, 2.2, 3.3);
6 return printf("answer = %f", answer);
7 }
8 double sum(double a, double b, double c)
9 {
10 return(a + b + c);
11 }
12 A. The name sum conflicts with a standard ANSI math function.
13 B. The return statement in fx returns type double.
14 C. Return statements may not contain an algebraic expression (a + b + c).
15 D. There is nothing wrong with the program.
16 E. The call to sum assumes that sum returns type int.
17
18 19. In C++, what gets printed?
19 (Note 5.7)
20 void print(int x = 1, int y = 2, int z = 3)
21 {
22 cout << x << y << z;
23 }
24 int main()
25 {
26 print(), print(4), print(5, 6), print(7, 8, 9);
27 return(EXIT_SUCCESS);
28 }
29 A. 123
30 B. 456789
31 C. 123456789
32 D. 123423563789
33 E. It won't compile.
34
35 20. In C++, predict what gets printed?
36 (Note 5.8)
37 void print(int x, int y = 2, int z = 3) { cout << x << y << z; }
38 void print(long x, int y = 5, int z = 6) { cout << x << y << z; }
39 int main()
40 {
41 print(4), print(4L);
42 return(EXIT_SUCCESS);
43 }
44 A. 44L
45 B. 423423
46 C. 423456
47 D. Output is implementation dependent.
48 E. It won't compile because the print function definitions are ambiguous.
49