You are on page 1of 4

EEP Workshop [25-27 February 2012]

CSE/IT/ECE Day 1: Class-review

Questions based on
Basics of C/C++ Programming, Tokens, Data Types, Operators, Control Statements, Arrays, Strings, Functions, Recursion
1 . The maximum no. of allowable characters in an external identifier according to ANSI C standard is: a. 8 b. 16 c. 31 d. 63 Which a. b. c. d. of the following is a valid char value? -129 -128 128 129

2 .

3 .

The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____. a. 14.8 b. 14 c. 13 d. 15 If a variable, num, contains the value 5, the values of the expression num and numis 4 and 5 respectively. a. True b. False Given a. b. c. a is 3, b is 4, and c is 5, what is the value of the expression--a * (3 + b) / 2 - c++ * b? -9 -10 -13 d. -8 e. Undeterminable as b is evaluated twice.

4 .

5 .

6 .

Given: enum bool {false, true}; int one; double two;bool four; Which of the following assignments are valid? (i) one = 7 * 3 % 4; (ii) 2.3 + 3.5 = two; (iii) four = (2 <= 3); a. Only (i) is valid b. (i) and (ii) are valid c. (i) and (iii) are valid d. (ii) and (iii) are valid The following statement creates an anonymous type: enum {1ST, 2ND, 3RD, 4TH} places; a. True b. False

7 .

Page 1 of 4

8 .

A(n) ____, called the selection/repetition symbol, is used in a flowchart to represent the selection structure. a. Parallelogram b. Rectangle c. Hexagon d. Diamond A variables ____, which can be either local or global, indicates which portions of a program can use the variable. A variables ____ indicates how long the variable remains in the computers memory. a. level, period b. lifetime, scope c. scope, lifetime d. type, duration The instruction:average = number1 + number2 / 2;is an example of a syntax error. a. True b. False The value of the expression (x = 18) has the same value as the expression (x == 18). a. True b. False Consider the following if else chain for printing a grade: if (score > 90) cout<< A <<endl; else if (score > 80) cout<< B <<endl; else if (score > 70) cout<< C <<endl; else cout<<Not passing <<endl; What is printed when score is 80? a. A b. B c. C d. Not Passing Which code fragment correctly expresses the following statement? For all employees under the age of 25 or over the age of 50, bonus is increased by 5%. Assume that the variables age and bonus have been initialized and are accessible by the code. a. if (age<25 && age>50) bonus = bonus*1.05; b. if (age<=25 || age=>50) bonus = bonus*1.05; c. if (age<25 || age>50) bonus = bonus*1.05; d. if (age>25 || age<50) bonus = bonus*1.05; How many times does the following C++ while loop execute? count = 1; while (count < 11) { cout<< count; count += 2; } a. 1 b. 5 c. 10 d. 11

9 .

1 0 . 1 1 . 1 2 .

1 3 .

1 4 .

Page 2 of 4

1 5 .

Which a. b. c. d.

of the following is true in context of for loop: Exactly two semicolons are required in for At least two semicolons are required in for At most two semicolons are required in for 0 or more semicolons may be put in for

1 6 . 1 7 . 1 8 . 1 9 .

The statement while (count <= 10) { ... } is equivalent to the statement do { } while (i>10); a. True b. False You can code the pretest loop in C++ using the while statement, but not the for statement. a. True b. False The exit statement can be used to terminate a called function and return to the calling function a. True b. False When a variable is passed by ____, only the value stored in the variable is passed to the function. a. Value b. Reference c. Output parameter d. Default parameter Initializer values for an array are enclosed in brackets ([...]). a. True b. False Which of the following statements about multidimensional arrays is false? a. Declaration tells the compiler the name of the array, the type of the elements, and the size of each dimension. b. The definition for a fixed-length array requires a constant for each dimension except the first. c. Fixed-size arrays can be initialized; variable-sized arrays cannot. d. The definition for a variable-length array requires a variable for each dimension. e. When a multidimensional array is initialized, the first and only the first dimensions size does not need to be specified when explicit initialization is used. Given the declaration int list[20]; the statement list[12] = list[5] + list[7]; updates the content of the twelfth component of the array list. a. True b. False Which keyword is used before the array declaration in a function heading to prevent the function from modifying the array. a. fixed b. extern c. const d. static Assume that you have the following declarations. int alpha[100], beta[25][4]; In this declaration, the array alpha has less elements than the array beta. a. True b. False In the a. b. c. d. declaration int gamma[5][6][10]; the array gamma has: 21 elements and 3 dimensions 3 elements and 21 dimensions 3 elements and 300 dimensions 300 elements and 3 dimensions

2 0 . 2 1 .

2 2 . 2 3 .

2 4 .

2 5 .

Page 3 of 4

2 6 .

Which of the following declarations correctly declares a two dimensional array of doubles named prices that has 10 rows and 5 columns? a. constint NUMROWS = 10; constint NUMCOLS = 5; double prices[NUMROWS + NUMCOLS]; b. constint NUMROWS = 10; constint NUMCOLS = 5; double prices[NUMROWS,NUMCOLS]; c. constint NUMROWS = 10; constint NUMCOLS = 5; double prices[NUMCOLS][NUMROWS]; d. constint NUMROWS = 10; constint NUMCOLS = 5; double prices[NUMROWS][NUMCOLS]; The function below performs a linear search on an array of integers. If the key is found, the items location in the list is returned. Otherwise a -1 is to be returned. Where should the statement, return -1;, appear in the code? intlinearSearch(int list[], int size, int key) { int i; PLACE 1 for (i = 0; i < size; i++) { PLACE 2 if (list[i] == key) return i; PLACE 3 } PLACE 4 } a. PLACE 1 b. PLACE 2 c. PLACE 3 d. PLACE 4 To reference fields within a structure identified by a pointer, we use the operator: a. :: b. .* c. -> d. . Which of the following string declarations is invalid? a. char str[9] = "Good Day"; b. char str = "Good Day"; c. char str[ ] = "Good Day"; d. char* str = "Good Day"; The declaration char codes[] = sample creates a character array named codes having six elements and fills the array with the six characters in the string sample. a. True b. False

2 7 .

2 8 . 2 9 .

3 0 .

Page 4 of 4

You might also like