Programming Final Exam
If x = 3, which of the following "C" statements sets x to 7? a. x *= 4; b. x += 4; c. x =+ 4; d. x + 4 = x e. x + 4;
B
Which of the following is a poor programming practice? a. Indenting the statements in the body of an "if" statement b. Using a floating-point value as the counter in a "for" statement c. Using more than one level of nesting d. Placing blank lines above and below control statements e. Documenting every function
B
Which of the following statements about the inclusion of <stdio.h> is false? a. this header file contains information and declarations used by the compiler when compiling standard input/output library functions such as printf( ). b. it is required in every program. c. this header file contains many useful library functions. d. at pre-processing time, the content of this header file are made a part of the current program.
B
The for statement header. for (i = 1; i < 100; ++i) performs the body of the loop for... a. values of the control variable from 1 to 100 in increments of 1 b. values of the control variable from 1 to 99 in increments of 1 c. values of the control variable from 0 to 100 in increments of 1 d. values of the control variable from 0 to 99 in increments of 1
B (++i means you're doing the increment before you do the testing)
In printf("..."), which of the following formatting string would print the value of 2.3 as 002.300? a. %-7f b. %-7f.3 c. %07.3f d. f3.7% e. f7.3%
C
Which assignment expression is equivalent to c = c/2? a. c / = 2 b. c / c = 2 c. c /= 2 d. c =/ 2
C
Which is NOT an iteration statement? a. for b. while c. do...while d. while...do...
D
Which of the following scanf(...) statements correctly reads the two integers that are included in the following stream of characters: 1234#43210 a. scanf("%d %d", num1, num2); b. scanf("%d%d," num1, num2); c. scanf("%d%d", &num1, &num2); d. scanf("%d %d", &num1, &num2);
D
Which statement about comments is false? a. comments may begin and end with /* */, respectively. b. programmers insert comments to document programs and improve program readability. c. comments do not cause any machine language object code to be generated. d. every line of code should be documented.
D
Which statement is true? a. The conversion specifier "%7.2f" prints a floating-point value with a field width of 10 positions. b. The conversion specifier "%7.2f" prints a floating-point value with 7 positions to the left of the decimal point. c. The conversion specifier "%7.2f" prints a floating-point value with 5 positions to the left of the decimal point. d. The conversion specifier "%7.2f" prints a floating-point value with 4 positions to the left of the decimal point.
D
Which of the following if statements is syntactically Correct? a. if x = 3 x++; b. if (3=x), x++; c. if (3==x), x++; d. if (x==3 ++x); e. if (x++ ==3) x++;
E
p, q, and r are three logical statements that are all True. Would the following be True or False? (p AND NOT q) AND (p AND q AND r)
FALSE
KNOW HOW TO DRAW A STRUCTURE CHART
KNOW HOW TO DRAW A STRUCTURE CHART
What must every C program have?
Main
Consider the partial code; int a = 0; int b = 1; int c = -1; if (!c) printf("%d", b); What is printed by this code?
Nothing is printed
In C, assuming that s1 = True, s2 = False, and s3 = False, would the following expression be True or False? s2 || !s1 || !(s3 && s1)
True
What is wrong with the following loop? While (sum <= 1000) {sum = sum + 30;}
While should be while (should not be capitalized)
In a printf( ) a backslash is printed by enclosing __________ in quotes.
\\
A programmer intentionally creates a for-loop with the following "for" header: for (;;) The programmer's intent was most likely to create...
an infinite loop
A programmer intentionally creates a for-loop with the following for header: for (; ;) The programmer's intent was most likely to create...
an infinite loop
How many times will the following program print the word "hello"? int i = 1; while (i<=10) {printf("hello");}
an infinite number of times
What is NOT a valid integer value?
any decimal point because they are FLOATS
The smallest data item in a computer, called a _______, can assume the value 0 or the value 1.
bit
What assignment expression is equivalent to c = c/2?
c /= 2
What statement is used to skip the remainder of the body of an iteration statement and proceed with the next iteration of the loop?
continue (break kills the whole thing and jumps AFTER the loop)
In a flowchart, what is the shape of the decision symbol?
diamond
What will this program print? #include <stdio.h> #include <stdlib.h> struct house {float sqft; int rooms; int stories; char *address; }; int main(void) { struct house armstrong; armstrong.address = "22 Bailey Rd"; printf("%c", armstrong.address[7]); return 0; }
e
What is an INVALID identifier (variable name)?
ex: 5test (because it begins with a number) ex: _test (this works, but it is not recommended)
What statement includes all the details of counter-controlled iteration, such as Initial Value, Condition for Iteration, and Increment/Decrement?
for
In the statement below, int main( ) the parentheses indicate that main is a program building block called a ___________.
function
In flowcharting, what does the parallelogram shape represent?
input/output
What is an INCORRECT way to initialize an array?
int n[5] = {0, 7, 0, 3, 8, 2};
In the following program, some lines have been identified in the comments, and one of these lines has a syntax error. Which line has the error? int main() /*line 1*/ {int num; printf("Enter a real number: \n"); /*line 2*/ scanf("%f", num); /*line 3*/ printf("%f", num); /*line 4*/
line 3 (supposed to be scanf("%f", &num);)
Consider the partial code: int a = 1, b = 0, c = -1, d = -2; if (a < c) printf("less"); if (a > b) printf("more"); if (a != d) printf("not equal"); What is printed by this code?
morenot equal
Having a loop within a loop is known as...
nesting
The program segment int counter = 1; do { printf("%d", counter); } while (++counter <= 10); will _____________.
print the numbers 1 through 10
Every statement in C must end with a...
semicolon(;)
When a new value gets assigned to a variable that already has an old value, ________________________________________________________.
the new value overwrites the old value at that memory location.
What's wrong with this line of code? int[] = (1, 2, 3, 4, 5);
the parentheses should be curly braces
An uninitialized variable contains _________________.
the value last stored in the memory location reserved for that variable
A _______________ is a location in the computer's memory where a value can be stored for use by a program.
variable
A switch statement should be used...
when a variable may assume many different values which must be tested
In the language of "C", a false condition is evaluated to...?
zero (0)
What will be the value of d in the following program? #include <stdio.h> int main() { int a = 10, b = 5, c = 5; int d; d = b + (c==a); printf("%d", d); }
5 because it would be: d = 5 + (5=10) d = 5 + F or d = 5 + 0 d = 5 :)
What will be the value of f in the following program? #include <stdio.h> int main() { int a = 10, b = 5, c = 5; float f; f = b*1.0 + c / a; printf("%f", f); }
5.000000
Consider the following code, assuming that x is an integer variable with an initial value of 12: if (x=6) { printf("%d", x); } What is the output?
6
Examine the partial "C" code: const int a_length = 10; int a[a_length]; int count; for (count = 0; count < a_length; count++) a[count] = 2 * count; At the conclusion of this code, what will be the value of a[4]?
8
How many letters of "X" are printed? int i, j, k; for (i = 1; i <= 2; i ++) for (j = 1; j <= 2; j++) for (k = 1; k <+ 2; k++) printf("X");
8 (nested loops = multiplicative fact)
What is the FINAL value of x after performing the following operations? int x = 21; double y = 6; double z = 14; y = x/z; x = 5.5*y;
8.25 (double = doubling the float) when you're diving an integer by a float, the answer is a float.
Which of the following is a logical equality operator a. == b. = c. > d. >=
A
Which of the following will NOT increment the variable c by one? a. c + 1; b. c++; c. ++c; d. c+=1; e. c = 1 +c;
A (the result is c+1 but the value of c does not change)
How many times will the following program print hello? i = 1; while (i<=10) { printf("hello"); }
An infinite amount of times --> because there is no increment and the condition is always true
What operation will find the remainder when 15 is divided by 6?
% (15%6 = 3)
What is the value of i after the execution of the code: int i, j, k; for (i = 1; i <= 2; i ++) for (j = 1; j <= 2; j++) for (k = 1; k <= 2; k++) printf("X");
3
Write the decimal number 3.75 in binary.
11.11
How many int locations are reserved by the following declaration? int multiarray[5][5][5];
125
To what number would "C" evaluate the following arithmetic expression? 5/2.0
2.5
Evaluate the expression below: 3*4%6+4*5
20
What is an iteration/loop statement?
- do...while - for if and if...else are NOT looping statements!
Lines beginning with a # are processed _______________.
... at preprocessor time.
When the following code is executed, what will be the value of the variable named "val"? int a = 1; int b = 10; float c = -1.0; int val = (a <= b) && (c != 0);
1
The "for" statement header for (i = 1; i < 100; ++i) performs the body of the loop for when values of the control variable vary from...
1 to 99 in increments of 1
Write the following binary number in scientific notation: 11.011
1.1011x2^1
Consider the following correct segment of a correct C program: p=2; while (p<1000) { p = 2*p; } What is the value of p AFTER this while loop completes its execution?
1024 because the numbers are always going to end in even digits, and anything higher than in the thousands is incorrect because of the condition