Intro to Programming - Chapter 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

T or F In C, the remainder operator is %.

False

Evaluate the expression 3 * 4 % 6 + 4 * 5 (a) 20 (b) 26 (c) 12 (d) 32

(a) 20

Which of the following is an equality operator? (a) == (b) = (c) > (d) >=

(a) ==

Which statement prints "hi" on the screen? (a) puts("hi"); (b) put "hi"; (c) puts "hi"; (d) none of the above

(a) puts("hi");

When a number gets assigned to a variable that already has a value __________. (a) the new number overwrites the previous value at that memory location (b) the new number gets assigned to a neighboring memory location (c) the computer issues an error (d) the new value is destroyed and the old value remains

(a) the new number overwrites the previous value at that memory location

The __________ sign is also known as the __________ operator. (a) +, assignment (b) =, assignment (c) *, stream manipulator (d) &, stream insertion

(b) =, assignment

Every statement in C must end with a (a) period (.) (b) semicolon (;) (c) colon (:) (d) backslash (/)

(b) semicolon (;)

Which of the following is an invalid identifier (variable name)? (a) _Test (b) TEST (c) 5test (d) test1

(c) 5test

T or F The equality operators have a higher level of precedence than the relational operators.

The equality operators have a higher level of precedence than the relational operators.

T or F A good programming practice is to break a line after a comma in a lengthy comma-separated list.

True

T or F This header file contains information and declarations used by the compiler when compiling standard input/output library functions such as print.

True

T or F This header file contains information that helps the compiler determine

True

T or F This header helps locate bugs in your program at compile time, rather than at execution time (when errors are usually more costly to correct).

True

T or F Uppercase and lowercase letters are different in C.

True

T or F Whitespace characters such as tabs, newlines and spaces are generally ignored by the C compiler.

True

T or F in the statement sum = integer1 + integer2; both = and + are binary operators.

True

T or F sum = integer1 + integer2; involves destructive read-in.

True

T or F Identifiers can be of any length

True

Which of these is not a valid identifier? a) a_valid_identifier b) a1_valid_identifier c) a_valid_identifier_ d) 1_valid_identifier

a) a_valid_identifier

Which statement about C arithmetic is false? a) 6 / 3 yields 2 b) 5 / 2 yields 2.5 c) 7 % 3 yields 1 d) 6 % 3 yields 0

b) 5 / 2 yields 2.5

Which statement is false? a) In algebra, we write ab to multiply a times b. b) In C, we write ab to multiply a times b. c) In C, the remainder operator is %. d) In C, integer division yields an integer result.

b) In C, we write ab to multiply a times b.

Which of the following multiple word variable names does not conform to the good programming practices in the text? a) multiple_word_variable_name b) multipleWordVariableName c) multiplewordvariablename d) aReallyReallyLongMultipleWordVa

c) multiplewordvariablename

The following line is most properly an example of a __________. puts( "Welcome to C!" ); a) function b) block c) statement d) header

c) statement

A(n) __________ is a location in the computer's memory where a value can be stored for use by a program. a) unknown b) name c) variable d) declaration

c) variable

The address operator is a) && b) % c) @ d) &

d) &

T or F In C, we write ab to multiply a times b.

False

T or F In a printf statement, the comma that separates the format control string from the expressions to be printed is placed inside the format control string.

False

T or F Lengthy comments can cause poor execution-time performance.

False

T or F Nested, or embedded parentheses are evaluated last.

False

T or F Reading a value out of a memory location destroys that value.

False

T or F The C standard library provides function power to perform exponentiation.

False

T or F The equals sign (=) is not an operator.

False

T or F The expression a * (b + c) + c * (d + e) contains nested parentheses.

False

T or F The statements in an if statement must be indented.

False

T or F Variables may be defined anywhere in the body of main.

False

T or F When we say evaluation of an expression proceeds from left to right we are referring to the additivity of the operators.

False

T or F identifier and IdEnTiFiEr are identical identifiers in C.

False

T or F All the relational operators have the same level of precedence.

True

T or F All variable definitions must include the name and data type of each variable.

True

T or F All variables must be defined before they are used.

True

T or F C is case sensitive.

True

T or F Calculations can be performed inside printf statements.

True

T or F Comments begin and end with /* and */, respectively.

True

T or F Comments do not cause any machine language object code to be generated.

True

T or F Each variable being input in a scanf statement is generally preceded by an &.

True

T or F Each variable being output in a printf statement is generally not preceded by an &.

True

T or F Executable C statements either perform actions or make decisions.

True

T or F If the condition in an if statement is met, the statement in the body of the if statement is executed.

True

T or F In C, integer division yields an integer result.

True

T or F In algebra, we write ab to multiply a times b.

True

T or F It is not correct to split an identifier with a space, a tab or a newline.

True

T or F Multiplication has a higher precedence than addition.

True

T or F Parentheses may be used to force the order of evaluation to occur in any sequence desired by the programmer.

True

T or F Placing a blank line before and after every control structure can improve program readability.

True

T or F Programmers insert comments to document programs and improve program readability.

True

T or F Reading a value into a memory location destroys the previous value.

True

T or F Several variables of the same data type may be defined in one definition

True

T or F Statements and comments may be split over several lines.

True

T or F Subtraction has a lower precedence than division.

True

T or F The expression y = a * x * x + b * x + c does exponentiation without an exponentiation operator.

True

T or F There can be (but should not be) more than one statement per line

True

Which of the following statements is true in secure C programming? (a) You should avoid using printf to display a single string argument. (b) You should always use printf to display a single string argument. (c) You should always use puts to display a single string argument. (d) None of the above.

(a) You should avoid using printf to display a single string argument.

C's if statement executes the statement inside its body if a specified __________ is __________. (a) condition, true (b) condition, false (c) equality operator, true (d) relational operator, true

(a) condition, true

Variable names actually correspond to __________. (a) locations in the computer's memory (b) operators (c) integers (d) data types

(a) locations in the computer's memory

Which of the following must every C program have? (a) main (b) #include (c) /* (d) <stdio.h>

(a) main

Which operation will find the remainder when 15 is divided by 6? (a) 15 / 6 (b) 15 % 6 (c) 15 ^ 6 (d) 15 * 6

(b) 15 % 6

Which of the following is not a valid escape sequence? (a) \n (b) \\ (c) \~ (d) \"

(c) \~

Which of the following statements should be used in secure C programming to display the string "Welcome" not followed by a newline character? (a) printf( "Welcome" ); (b) puts( "Welcome" ); (c) printf( "%s", "Welcome" ); (d) None of the above.

(c) printf( "%s", "Welcome" );

Which of the following is not a valid integer value? (a) -3 (b) 0 (c) 2134859 (d) 1.1

(d) 1.1

Which of the following statements about the inclusion of <stdio.h> is false? a) It is required. b) This header file contains information and declarations used by the compiler when compiling standard input/output library functions such as printf. c) This header file contains information that helps the compiler determine if calls to library functions have been made correctly. d) This header helps locate bugs in your program at compile time, rather than at execution time (when errors are usually more costly to correct).

a) It is required.

Which statement is false? a) The assignment operator associates from left to right. b) The arithmetic operators associate from left to right. c) The equality operators associate from left to right. d) The relational operators associate from left to right.

a) The assignment operator associates from left to right.

Which statement is false. a) Variables may be defined anywhere in the body of main. b) All variables must be defined before they are used. c) All variable definitions must include the name and data type of each variable. d) Several variables of the same data type may be defined in one definition

a) Variables may be defined anywhere in the body of main.

Considering the following variable declarations: int a = 9; int b = 2; What result should be expected for (a/b)? a. The result will be 4 because (a/b) produces an integer (truncated result). b. The result will be 4.5 because (a/b) produces a float data type. c. The result will be 4.5 because (a/b) produces a double data type. d. There will be no result because (a/b) produces a compilation-time error.

a. The result will be 4 because (a/b) produces an integer (truncated result).

A character is a number that represents a letter, a number or a symbol. Which of the following is the best syntax to assign the character T to a char variable? a. character = 'T'; b. character = \T; c. character = "T"; d. character = \\T;

a. character = 'T';

Which statement about precedence is false? a) Parentheses may be used to force the order of evaluation to occur in any sequence desired by the programmer. b) Nested, or embedded parentheses are evaluated last. c) Multiplication has a higher precedence than addition. d) Subtraction has a lower precedence than division.

b) Nested, or embedded parentheses are evaluated last.

Which of the following is false? a) Reading a value into a memory location destroys the previous value. b) Reading a value out of a memory location destroys that value. c) sum = integer1 + integer2; involves destructive read-in. d) The statement in part c) also involves nondestructive read-out.

b) Reading a value out of a memory location destroys that value.

Which expression is true? a) The expression a * (b + c) + c * (d + e) contains nested parentheses. b) The expression y = a * x * x + b * x + c does exponentiation without an exponentiation operator. c) The C standard library provides function power to perform exponentiation. d) When we say evaluation of an expression proceeds from left to right we are referring to the additivity of the operators.

b) The expression y = a * x * x + b * x + c does exponentiation without an exponentiation operator.

Which statement is false? a) Whitespace characters such as tabs, newlines and spaces are generally ignored by the C compiler. b) The statements in an if statement must be indented. c) Placing a blank line before and after every control structure can improve program readability. d) There can be (but should not be) more than one statement per line

b) The statements in an if statement must be indented.

In a printf, a backslash is printed by enclosing in quotes a) \ b) \\ c) /\ d) //

b) \\

The escape sequence for horizontal tab is __________. a) \tab b) \t c) \horizontaltab d) \T

b) \t

The pair of braces that delineate the body of main and the portion of the program between these braces is called a __________. a) function b) block c) statement d) header

b) block

The precedence for arithmetic operations is the following: a) 1. parentheses; 2. addition and subtraction; 3. multiplication, division and remainder; 4. assignment. b) 1. assignment. 2. parentheses; 3. multiplication, division and remainder; 4. addition and subtraction; c) 1. parentheses; 2. multiplication, division and remainder; 3. addition and subtraction; 4. assignment. d) 1. parentheses; 2. Multiplication and division; 3. Addition, subtraction and remainder; 4. assignment.

c) 1. parentheses; 2. multiplication, division and remainder; 3. addition and subtraction; 4. assignment.

Which of the following is false? a) Each variable being input in a scanf statement is generally preceded by an &. b) Each variable being output in a printf statement is generally not preceded by an &. c) In a printf statement, the comma that separates the format control string from the expressions to be printed is placed inside the format control string. d) Calculations can be performed inside printf statements.

c) In a printf statement, the comma that separates the format control string from the expressions to be printed is placed inside the format control string.

Which statement is false? a) It is not correct to split an identifier with a space, a tab or a newline. b) Statements and comments may be split over several lines. c) The equals sign (=) is not an operator. d) A good programming practice is to break a line after a comma in a lengthy comma-separated list.

c) The equals sign (=) is not an operator.

Which statement is false? a) in the statement sum = integer1 + integer2; both = and + are binary operators. b) The statement in part a) is an example of an assignment statement. c) The spaces around each of the binary operators in the statement of part a) are required. d) In part a), the = operator's two operands are sum and the value of the expression integer1 + integer2.

c) The spaces around each of the binary operators in the statement of part a) are required.

Every variable has all the attributes below, except a) name b) value c) alias d) type

c) alias

Lines beginning with a # are processed a) at execution time. b) at compile time. c) at preprocessor time. d) at postprocessor time.

c) at preprocessor time.

Which of the following is not a synonym for a C string? a) message b) character string c) character d) literal

c) character

Which of the following statements is false? a) C is case sensitive. b) Uppercase and lowercase letters are different in C. c) identifier and IdEnTiFiEr are identical identifiers in C. d) Identifiers can be of any length

c) identifier and IdEnTiFiEr are identical identifiers in C.

Which statement about comments is false? a) Comments begin and end with /* and */, 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) Lengthy comments can cause poor execution-time performance.

d) Lengthy comments can cause poor execution-time performance.

Which statement is false? a) Executable C statements either perform actions or make decisions. b) If the condition in an if statement is met, the statement in the body of the if statement is executed. c) All the relational operators have the same level of precedence. d) The equality operators have a higher level of precedence than the relational operators.

d) The equality operators have a higher level of precedence than the relational operators.

a * ( b + c ) may also be written in C as a) ab + ac b) (a * b ) + c c) a * b + c d) a * b + a * c

d) a * b + a * c

A linked program is often called a(n) __________. a) chain b) library c) object d) executable

d) executable

The order in which statements are __________ is called flow of control. a) entered in a source file b) preprocessed c) compiled d) executed

d) executed

In the line int main() the parentheses indicate that main is a program building block called a a) module b) statement c) directive d) function

d) function

Which of the following is not a keyword? a) int b) return c) if d) main

d) main

Which of the following error is not an example of compilation-time error? a. Spelling. b. Matching of parentheses. c. punctuation. d. Division by zero.

d. Division by zero.

What result should be expected for the following code? #include <stdio.h> #define DIVIDE(a, b) (a / b) int main () { printf("Result = %d. \n", DIVIDE(5 + 4, 2 + 1)); return 0; } a. Result = (a, b). b. Result = DIVIDE(5 + 4, 2 + 1). c. Result = 3. d. Result = 8.

d. Result = 8.

What result should be expected for the following snippet? int a, b; a = 9; b = 2; a /= b++; printf("a = %d, b = %d.", a , b); a. a = 3, b = 2. b. a = 3, b = 3. c. a = 4, b = 2. d. a = 4, b = 3.

d. a = 4, b = 3.

Which of the following is not a definition/declaration of a constant? a. # define NUMBER 155 b. const int NUMBER = 155; c. const int number = 155; d. int number = 155;

d. int number = 155;


Kaugnay na mga set ng pag-aaral

Ceramic Materials- Lithium Disilicate vs Zirconia

View Set

the vestibular system (end of chapter 7)

View Set

8th Grade my Perspectives ELA End-of-Year Test (Online)

View Set

Saunders Integumentary Problems (Ch 43) Practice Questions

View Set