=========================preview======================
(SummerProgrammingCourse)[2009](sum)midterm~whliaa^_10125.pdf
Back to SUMMERPROGRAMMINGCOURSE Login to download
======================================================
(To be completed by TA)

Number:






The Hong Kong University of Science and Technology
Summer Programming Course 2009 - HKUST
Summer 2009
Midterm Examination
Monday, July 27, 2009 1:30PM C 3:30PM

Name: _______________ Student ID: _____________ Email: ____________________

Instructions:
1. This is a closed-book, closed-notes examination.
2. Write your name, student ID and email on this page.
3. Check that you have all 14 pages.
4. Answer all questions using the space provided after each question.
5. All programming questions are in C++.

Question
Score

1

/24

2

/6

3

/12

4

/16

5

/8

6

/12

7

/10

8


/12

Total

/100



Question 1 (24 marks) True-or-False

Indicate whether the following statements are true or false by circling T or F. You get 2 points for each correct answer, -2 for each wrong answer, and 0 if you do not answer. (Remark: statistically speaking, guessing does not help if you do not know the correct answer)
Note: All the questions are based on C++.
T/ F
(a)
The following expression is true.

(10/2 < 11/2)




T/ F
(b)
The following expression is true.

(1 | (1==2))



T/ F
(c)
A double variable can store a larger range of values than a float variable can.





T/ F
(a)
Given: char A[] = abcde

cout<<*(A+2)<<endl;



The above code prints b.

T/ F
(a)
Given: char A[] = abcde




A is a constant pointer.

T/ F
(a)
Given: int* const A;




A is a pointer and it can point to a variable of type const int

T/ F
(a)
A constant pointer cannot point to a constant variable.





T/ F
(a)
In dynamic memory allocation, memory is allocated from the heap.





T/ F
(a)
A pointer of any type can be a dangling pointer.





T/ F
(a)
In the header file, an inline function should be defined instead of just declared.




T/ F
(b)
In the compiling process, the preprocessor processes the source and header files, before the compiler compiles the code.




T/ F
(b)
Given: int* A[] = new int[x];


The above code refers to dynamic memory allocation. The size variable x must be a constant.













Question 2 (6 marks) Pre-Increment and Post-Increment

Consider the following code:

int a, b, c