Anda di halaman 1dari 14

Chapter 4 Writing Programs Question Bank

Chapter 4 Writing Programs


Multiple Choice Questions

(U02C04L01Q001)
Which of the following is NOT a reserved word?
A. else
B. do
C. case
D. copy
Answer
D

(U02C04L01Q002)
Which of the following identifiers are VALID?
(1) FirstExamination
(2) Test2
(3) 3rdExamination
A. (1) and (2) only
B. (1) and (3) only
C. (2) and (3) only
D. (1), (2) and (3)
Answer
A

(U02C04L01Q003)
Which of the following is NOT the basic part of a C program?
A. global declaration
B. main function
C. preprocessor directives
D. program ending
Answer
D

Computer & Information Technology for HKCEE 1 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L01Q004)
Which of the following pair of symbols is used to enclose comments in C?
A. /* ... */
B. (…)
C. { ... }
D. *... *
Answer
A

(U02C04L01Q005)
Which of the following is a valid identifier for holding the class number of a student?
A. ClassNumber
B. Class Number
C. Class-Number
D. Class@Number
Answer
A

(U02C04L01Q006)
Which of the following statements can declare a constant Rate which has a value equal to 5%?
A. #define RATE 5%;
B. #define RATE .05;
C. #define RATE 5;
D. #define RATE (5/100)%;
Answer
B

(U02C04L01Q007)
Which of the following statements can declare a string variable Student?
A. int student;
B. float student;
C. char student;
D. char student[10];
Answer
D

Computer & Information Technology for HKCEE 2 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L01Q008)
Which data type is the most suitable for holding the student number 0041123?
A. int student_number;
B. float student_number;
C. char student_number[7];
D. char student_number;
Answer
C

(U02C04L01Q009)
Which of the following is NOT a data type in C?
A. integer
B. character
C. Boolean
D. floating point
Answer
D

(U02C04L01Q010)
Which of the following is not a character constant in C?
A. ‘C‘
B. ‘ ‘
C. ‘CC‘
D. ‘?‘
Answer
C

(U02C04L01Q011)
The tool used by a programmer to convert a source program to a machine language object module is
a _____ .
A. linker
B. compiler
C. text editor
D. preprocessor
Answer
B

Computer & Information Technology for HKCEE 3 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L01Q012)
Which of the following contains the programmer’s original program code?
A. text file
B. object file
C. source file
D. executable file
Answer
C

(U02C04L01Q013)
C language is considered to be a _____.
A. high-level language
B. natural language
C. binary language
D. low-level language
Answer
A

(U02C04L01Q014)
In C language, which of the following is to assemble all the functions into the final executable
program?
A. linker
B. compiler
C. preprocessor
D. editor
Answer
A

(U02C04L01Q015)
The main function in every C language program is called
A. {
B. program
C. function
D. main
Answer
D

Computer & Information Technology for HKCEE 4 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L01Q016)
Which two sets of characters mark the beginning and ending points for a comment in the C
language?
A. ; and Enter
B. ( and )
C. /* and */
D. REM and MARK
Answer
B

(U02C04L01Q017)
Which of the following is NOT an escape character?
A. \a
B. \b
C. \\
D. \k
Answer
D

(U02C04L01Q018)
The following scanf statement can be replaced by
scanf("%s", city);
A. gets("%s");
B. gets(city);
C. gets("city");
D. gets("%s", city);
Answer
B

(U02C04L01Q019)
Which of the following printf statements would make noise?
A. printf("\arghghgh!\n");
B. printf("\table bangs!\n");
C. printf("she bangs!\n");
D. printf("Crash!\n");
Answer
A

Computer & Information Technology for HKCEE 5 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L01Q020)
What is the output of the following C statement?
printf("2%d ", 1 + 2);
A. 2%d
B. 1 + 2
C. 3
D. 3
Answer
D

(U02C04L01Q021)
What is the output of the following C statement?
printf("%10.3f ", (float)-77/52);
A. –1.480769
B. –1.4808
C. –1.481
D. –1.481
Answer
C

(U02C04L01Q022)
What is the output of the following C statement?
printf("a\ta\ta ");
A. a\ta\ta
B. aaa
C. a a a
D. syntax error
Answer
C

Computer & Information Technology for HKCEE 6 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L01Q023)
What is the output of the following C statements? (A and B are string variables.)
A = 'X';
B = 'Y';
printf(“AB%c%c”, A, B)
A. ABAB
B. ABXY
C. XYAB
D. XYXY
Answer
B

(U02C04L01Q024)
Which of the following mathematical functions cannot be found in the math.h?
(1) abs
(2) floor
(3) sqrt
A. (1) only
B. (1) and (2) only
C. (1) and (3) only
D. (2) and (3) only
Answer
A

(U02C04L01Q025)
What is the result of the following expression?
sqrt(abs(-144))
A. –12
B. 12
C. 144
D. error
Answer
B

Computer & Information Technology for HKCEE 7 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L01Q026)
What is the result of the following expression?
pow (3.0, 4.0)
A. 81.0
B. 27.0
C. 12.0
D. 7.0
Answer
A

(U02C04L01Q027)
Suppose variable x has a value 1234.56. Which of the following expressions return(s) value 0.56?
(1) x - floor(x)
(2) ceil(x) - x
(3) ceil(x) – floor(x);
A. (1) only
B. (2) only
C. (3) only
D. (1) and (2) only
Answer
A

Computer & Information Technology for HKCEE 8 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

Conventional Questions

(U02C04L02Q001)
Consider the following program.
#include <stdio.h>
void main ( ){
int a, b;
printf("Enter 2 integers: ");
scanf("%d%d", &a, &b);
printf("The mean of A and B is %7.2f\n", (float)(a + b)/2);
}
List all the
(a) reserved words,
(b) identifiers.
(8 marks)
Answers
(a) void, int, float
(b) a, b, main, printf, scanf

(U02C04L02Q002)
Complete the following program by filling suitable reserved words or identifiers in the blanks.
#_(a)_ <stdio.h>
void _(b)_ ( ){
_(c)_ name[6] = "Peter";
_(d)_ age;
age = 16;
_(e)_ ("%s is %i years old. ", _(f)_, age);
}
(6 marks)
Answers
(a) include
(b) main
(c) char
(d) int
(e) printf
(f) name

Computer & Information Technology for HKCEE 9 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L02Q003)
State the C-implementation that is the most suitable for the following data.

Data Example
(a) Height in metre 1.65
(b) The value of π 3.1415926536
(c) Sex M
(d) Number of students in a class 40
(e) Long integer 123456789
(5 marks)
Answers
(a) float
(b) double
(c) char
(d) int
(e) long int

(U02C04L02Q004)
State whether each of the following words is a valid or an invalid identifier. Explain if it is invalid.
(a) Z
(b) @
(c) Class Number
(d) Class-Number
(e) Number2
(f) 2Names
(g) if
(7 marks)
Answers
(a) Valid.
(b) Invalid. Symbol ‘@’ is not allowed.
(c) Invalid. Blank space is not allowed.
(d) Invalid. Symbol ‘-‘ is not allowed.
(e) Valid.
(f) Invalid. An identifier must start with a letter.
(g) Invalid. Reserved words cannot be used as identifiers.

Computer & Information Technology for HKCEE 10 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L02Q005)
Consider the following variable declaration.
int score[40];
(a) What is the name of the array?
(b) What is the lower bound index?
(c) What is the upper bound index?
(d) What is the data type of the array?
(e) How many elements are there in the array?
(f) Write down the identifier of the first element.
(g) Write down the identifier of the 5th element.
(h) Write down the identifier of the last element.
(8 marks)
Answers
(a) score
(b) 0
(c) 39
(d) integer
(e) 40
(f) score[0]
(g) score[4]
(h) score[39]

Computer & Information Technology for HKCEE 11 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L02Q006)
(a) What is the preprocessor directive in a C program?
(b) Write the constant declaration of the program according to the table below.

Name of Constant Data Type Value


School string ‘ABC School’
NumberOfStudent integer 1024

(c) Write the declaration part of the program according to the following table.

Name of Variable Data Type Meaning


Book string Book title of no more than 40
characters
Price float Price of the book
NumOfPage integer Number of pages
AuthorName string Name of an author of no more
than 25 characters
BookIndex numeric array 1000 book index stored in
integer array

(11 marks)
Answers
(a) The preprocessor directive is a special instruction to the preprocessor that tells it how to
prepare the program for compilation.
(b) const char[11] = "ABC School";
const int NumOfStudent = 1024;
(c) char Book[40];
float price;
int NumOfPage;
char AuthorName[25];
int BookIndex[1000];

Computer & Information Technology for HKCEE 12 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L02Q007)
What is #include in a C program and what does it do?
(2 marks)
Answers
#include is a preprocessor directive. It tells the compiler to “include” another program or errors
that would otherwise occur.

(U02C04L02Q008)
In C language, what is the same function of gets and scanf and what are their differences?
(3 marks)
Answers
Both gets and scanf read characters from the keyboard and save them in a variable.
gets only reads in text, however, scanf can read in numeric values and strings and in a number
of combinations.

(U02C04L02Q009)
Write the printf escape sequences.

Descriptions Sequence
The speaker beeping \a
Tab
The apostrophe
The double-quote character
The backslash character
New line
Carriage return
The question mark

(7 marks)
Answers
Descriptions Sequence
The speaker beeping \a
Tab \t
The apostrophe \'
The double-quote character \"
The backslash character \\
Newline \n
Carriage return \r
The question mark \?

Computer & Information Technology for HKCEE 13 © Pearson Education Asia Limited 2004
(Module A1)
Chapter 4 Writing Programs Question Bank

(U02C04L02Q010)
Write the printf conversion characters.

Descriptions Conversion Character


String of text %s
Single character
Decimal integer
Floating-point value in E notation
Floating-point value
(4 marks)
Answers
Descriptions Conversion Character
String of text %s
Single character %c
Decimal integer %d
Floating-point value in E notation %e
Floating-point value %f

Computer & Information Technology for HKCEE 14 © Pearson Education Asia Limited 2004
(Module A1)

Anda mungkin juga menyukai