CS 161 Final Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What character do preprocessor directives begin with?

#

Which of the following are valid C++ operators?

% /

Given the input 82 What value would be in the variable ch after the following code executes?int x; char ch; cout << "Enter a character: "; cin >> ch;

'8'

If a char is 1 byte (which is common), what is the range of values it can store?

-128 to 127

If an int is 4 bytes (which is common), what is the range of values it can store?

-2,147,483,648 to 2,147,483,647

What characters are used to denote multi-line comments in C++? (Note: ellipses denote multiple lines of code)

/* ... */

What characters are used to denote a single line comment in C++?

//

What is the result of the following expression? 3 * 5 % 3

0

What is the result of the following expression? 7 % 2 (modulus is %)

1

One line of assembly results in how many lines of machine code?

1 (typically)

One line of a high level language, such as C++, results in how many lines of machine code?

1 to lots

How many bytes are in a Kilobyte (KB)?

1,024

What is the value of x after the following bit of code runs? int a=5; int b=3; x=a+b*2;

11

What is the result of the following expression? 2 * 3 - 2 * 2

2

What is the result of the following expression? 7 / 2

3

What is the result of the following expression? 1 + 5 / 2

3

What is the result of the following expression? 1 + 5 / 2 * 1.0

3.0

What is the result of the following expression? 1 + 5 / 2.0

3.5

What is the result of the following expression?7.0 / 2

3.5

What is the result of the following expression? 3 + 7 % 2

4

What is the result of the following expression? 1 + 2 * 4 - 3

6

What is the result of the following expression? 3 + 2 * 2

7

How many bits are in a byte?

8

Given the input 82 What value would be in the variable x after the following code executes?int x; char ch; cout << "Enter a number: "; cin >> x;

82

Which of the following is the extraction operator? (used to get data from an object, such as cin)?

>>

Given the following code is part a computer program, what language is the program written in? areaRectangle = length * width;

A high level language, such as C or C++

What are coding conventions? (i.e. programming conventions)

A set of guidelines followed by a group of programmers so that all of their code is of a similar style, thereby making maintenance easier

Given the ascii value 65 equates to 'A', what does the following code snippet print? char letter=65; letter++; cout << letter;

B

In C++, there are 4 categories of numeric data types (listed below as the answers). Types in which category are used to store true/false values?

Boolean

What is the result of the following expression?5.0 * 5 % 2

Compiler error.

Which of the following statements are true?

Complex, difficult to understand lines should have a comment clarifying their purpose Blocks of code should be preceded with a short comment describing what they do or why it's being done

Which of the following are true about declaring variables in C/C++?

Declaring a variable allocates memory to store some type of data The data type must be specified The variable name must be specified

Which of the following are true?

If an operator has two integer operands (e.g. 5/2), integer math is done and the result is an integer If an operator has two floating point operands (e.g. 5.0/2.0), floating point math is done and the result is a floating point number. If an operator has one integer and one floating point operand (e.g. 5 / 2.0), floating point math is done and the result is a floating point number.

In C++, there are 4 categories of numeric data types (listed below as the answers). Types in which category are used to store numbers that will not have decimal values, such as the number of students enrolled in a class?

Integer

Which of the following are true about the char data type?

It's used to store a letter, digit, or other symbol It takes up one byte of storage It actually stores the ASCII value (a number from 0-127) that represents the character being stored

What is the purpose of a high level language?

Make software development faster

Which of the following statements are true about order of operations?

Multiplication, division, and modulus are done first in the order they appear (from left to right), then addition and subtraction in the order they appear. Parenthesis can be used to change the order operations are done

What are identifiers?

Names of things, such as variables or functions

What does the following code snippet print?char letter="Z"; letter-=2; cout << letter;

Nothing, because the line "char letter="Z";" line is invalid.

Which of the following are legal variable names?

Planet3of8 planet_number_three

Who are source code comments for?

Programmers looking at the code in the future (which may include you!)

Which of the following are true about reserved words?

Reserved words are words that have special meaning in the programming language Reserved words cannot be used for anything other than than their defined purpose Many source code editors often display reserved words in a unique color so they can easily be seen/identified

Which of the following statements are true?

Self-documenting code entails using meaningful variable and function names that clearly describe their contents or functions If your code is self-documenting, fewer comments are needed Comments can lie; code never lies Self-documenting code is easier to debug than code that is not self-documenting

Which of the following are true?

The extraction operator skips all leading whitespace characters when searching for the next data in the input stream. In the statement cin >> x; x must be a variable. You generate the newline character by pressing the Enter (return) key.

Which of the following are true about constants?

They are declared using the const keyword They must be initialized when declared They cannot be changed once initialized Constant names are typed in ALL_CAPS by convention

Which of the following are true of programming conventions?

They are enforced by the company/instructor They are designed to make all the code created/maintained by a group of programmers look similar so it's easier to maintain They typically include rules on indentation, comments, naming conventions, white space, etc.

In C++, what are the rules (enforced by the compiler) regarding identifiers? (i.e. variable/function names)

They must begin with a letter or _ They may contain letters, numbers, and the _ They are case sensitive

Which of the following are legal variable names?

ThirdPlanetName PlanetName3 planetname

What is the primary purpose of adding comments to source code?

To make the code easier to understand

Which of the following are true about whitespace?

Whitespace includes blanks, tabs, and newlines Whitespace is used to make code more readable Almost all whitespace (except a single blank used to separate keywords and identifiers) is ignored by the compiler

What translates assembly to machine code?

assembler

Given the following code is part of a computer program, what language is the program written in? mov eax,dword ptr [length] imul eax,dword ptr [width] mov dword ptr [areaRectangle],eax

assembly code

What is the reserved word for the C++ boolean data type? (can only store true/false, which is really 1 (one) and 0 (zero))

bool

Which variable type would be best to store if a student was in class or not?

bool

Which of the following variable types could hold the value 5?

char int float double

There are 5 different signed integer types in C++. While the exact size of each isn't defined by the language (each compiler defines them), in general each of them can store a number bigger than the previous one. Which of the following lists them correctly from smallest to largest?

char, short, int, long, long long

What does the linker do?

combines object code from object files and libraries into an executable

Which of the following produce a .obj file?

compiler

Which of the following translates source code into object code?

compiler

What does the compiler do?

converts the (human-readable) source code into (cpu-readable) object code

Which of the following is the best name for a variable that will store how fast a car is currently travelling (and is an example of self-documenting code)?

currentSpeedMPH

Which variable type would be best to store the weight of a cat in pounds?

double

Which of the following would create a variable of type double and initialize it to 6 (and not generate any compiler warnings)?

double i=6; double i=6.0; double i = 6.0;

What does the following code snippet print? char letter='a'; letter = letter+4; cout << letter;

e

Which of the following is used by the programmer to enter a source program?

editor

Which of the following produce source code as their output?

editor pre-processor

What is output from the linker?

executable file

Which of the following variable types could hold the value 1.23?

float double

There are 3 different floating point data types in C++, each of which can store a number significantly larger then the previous. Which of the following lists them correctly from smallest to largest?

float, double, long double

What does the modulus operator (%) do?

gives you the remainder of integer division

Which of the following do the vast majority of software developers write their programs in?

high-level programming languages (C, C++, Java, etc..)

Which of the following are true about type conversions.

implicit conversion are those done automatically (such as when you multiple a float by an int; the system automatically converts the int to a float for the operation) explicit conversions are those the programmer specifically says to do (such as converting a float to an int so integer math would be done)

Which of the following variable types could hold the value 5000?

int double

Which of the following would create three integer variables? (named, albeit poorly, x, y, and z). Note: declaring multiple variables on one line is not usually a good idea.

int x; int y; int z; int x, y, z;

Which of the following would create a variable and initialize it to 6 (and not generate any compiler warnings)?

int x=6; int x = 6;

Where does the output from the preprocessor go?

into the compiler

What header file needs to be included to use cin and cout?

iostream

Which of the following combines the object code created from your source file, with object code from libraries, to create an executable?

linker

Which of the following produce an executable (.exe) file?

linker

Given the following hexadecimal numbers are actually executable lines from a computer program, what programming language is shown? a5 45 23 a6 6b 45 23 aa a5 23 ad 45

machine code

Which of the following does a CPU understand?

machine code

What does the preprocessor do?

modifies the source file as per the preprocessor directives (file includes, macro expansions, etc..)

What is output from the compiler

object file

Which of the following are input to the linker

object files libraries

Which of the following are legal variable names?

planet_number_three planetNumberThree _PlanetThree

Which of the following follows specific instructions in a source file and modifies the file accordingly (typically including other source code), before it's compiled?

pre-processor

Which of the following lists the correct order these items are ran in the build/run process?

preprocessor, compiler, linker, loader

What is the most difficult portion of the software development process?

problem analysis and algorithm design

What is input to the preprocessor?

source code

What is output from the preprocessor?

source code

When using cin, which of the following values will be treated as delimiters between input values?

spaces tabs carriage return/line feed (enter key)

Which of the following demonstrates how to cast myVariable to an int?

static_cast<int>(myVariable)

What kinds of errors can a compiler catch?

syntax errors

Which variable type would be best to store if a student was in class or not?

unsigned int

A common programming convention is to write self-documenting code. Which of the following variable declarations would be a good example of self-documenting code?

unsigned int totalStudents;

Integer types come in both signed (can store negative and positive values) and unsigned (can only store positive values). How do signed and unsigned types differ?

unsigned types have the keyword "unsigned" before them (e.g. unsigned int)

Which of the following are common programming conventions?

use ALL_CAPS for constant names camelCase variable/function names

In C and C++, if you don't initialize a variable, what value will it initially hold?

whatever value happened to be sitting in the memory location allocated to the variable

Why was assembly language invented?

writing in machine code was extremely tedious and error prone

When doing software development, if you combine the algorithm design step and writing code step

you'll waste time.


संबंधित स्टडी सेट्स

Pediatrics Exam 2: Wong Chapters 1, 2, 3, 11, 12, 17-20

View Set

Insurance Regulations - B. State Regulation

View Set

CLIPP cases - End of case Questions

View Set

Field Tech III - IV Conventional-TCP/IP SERVICES (190E50-3)

View Set

3 Staying in Hotels (Top Notch 2)

View Set

Ch: 1 Accounting- Information for Decision Making

View Set