3014 WORK

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Can be used to specify array sizes, thereby making programs more scalable.

Constant variables:

A function that modifies an array by using pointer arithmetic such as ++ptr to process every value should have a parameter that is:

A nonconstant pointer to nonconstant data.

A pointer can not be assigned to:

A pointer of a type other than its own type and void without using the cast operator.

A string array:

Is actually an array of pointers.

Which of the following statements is false about a function to which an array is being passed?

It always knows the size of the array that is being passed.

All of the following are reasons to use recursion except:

It maximizes execution performance.

Linear search is highly inefficient compared to binary search when dealing with:

Large, sorted arrays.

Choose the required parts of a function prototype:

List of data types it will receive The type of value the function will return Name of function The order of parameter types

An array is not:

Made up of different data types.

Enumeration constants:

Must have unique identifiers.

What does the following statement declare?

One pointer to an int and one int variable.

Which statement about insertion sort is true?

The algorithm is simple compared to other sorting procedures.

To prevent modification of array values passed to a function:

The array parameter can be preceded by the const qualifier.

Call-by-reference can achieve the security of call-by-value when:

The const qualifier is used.

After the ith iteration of the insertion sort:

The first i elements of the array are sorted

The argument list of a function call must match, or be consistent with, the parameter list of the called function in all of the following details, except:

The names of arguments/parameters in the list.

Arrays - Partial Initialization

If there are fewer values in the Initializer List then the remaining elements are initialized to zero If there are no values in the Initializer List then all elements are initialized to zero Following statement declares array num with 5 elements, and initializes ALL elements to zero (0): int num[5] = {0}; Following statement declares array n with 10 elements and initializes all elements to 0 int n[10] = {}; //initialize all elements of array n to 0

Assuming that t is an array and tPtr is a pointer to that array, which expression refers to the address of element 3 of the array?

&t[ 3 ]

Three of the following expressions have the same value. Which of the following expressions has a value different from the others'?

*ptr

Arrays - Processing

1.Initialize 2.input 3.Output 4.Sum and Average 5.Find largest element value 6.Find smallest element value

Given that k is an integer array starting at location 2000, kPtr is a pointer to k and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to?

2012

In order to perform file processing in C++, which header files must be included?

<iostream> and <fstream>

Which of the following C++ Standard Library header files does not contain a C++ Standard Library container class?

<string>

Select the false statement

A binary digit (bit) can store two values simultaneously.

What method should be used to pass an array to a function that does not modify the array and only looks at it using array subscript notation:

A constant pointer to constant data.

To follow the principle of least privilege, the selectionSort function should receive the array to be sorted as:

A constant pointer to nonconstant data.

Typically, which of the following contains the most data?

A database.

A function prototype can always be omitted when:

A function is defined before it's first invoked.

An activation record will be popped off the function call stack whenever:

A function returns control to its caller

An algorithm is:

A procedure for solving a problem in terms of the actions to execute. A procedure for solving a problem in terms of the order in which actions will execute

Which of the following is false?

A subscript cannot be an expression.

Which of the following does not have a stream associated with it?

All of the above have streams associated with them.

Linear search can be used on:

Any of the above.

The data hierarchy, arranged from smallest to largest, is:

Bit, byte, field, record, file.

Pointers may be assigned which of the following values?

Both (b) and (c)

Unless otherwise specified, entire arrays are passed __________ and individual array elements are passed __________.

By reference, by value.

Select the false statement.

C++ files include information about their structure.

A recursive function is a function that:

Calls itself, directly or indirectly.

Constant variables:

Can be used to specify array sizes, thereby making programs more scalable.

Referencing elements outside the array bounds:

Can result in changes to the value of an unrelated variable.

srand:

Can use the time function's return value as an optimal seed value.

In regards to default arguments, which of the following is false?

Default values cannot be global variables or function calls.

All of the following can cause a fatal execution-time error except:

Dereferencing a variable that is not a pointer.

An identifier's storage class:

Determines the period during which that identifier exists in memory.

Functions can:

Do all of the above.

Labels are the only identifiers with:

Function scope

Which of these describe the principle of least privilege?

Giving the client access only to the data that is necessary for the task and nothing more.

Each standard library has a corresponding:

Header file

A function prototype does not have to:

Include parameter names.

( *max )( num1, num2, num3 );:

Is a call to the function pointed to by max.

Which statement is not true about 0, z , %, * and Q?

Only three of the elements listed are in typical character sets.

Which of the following is not a disadvantage of trying to modify a sequential access file?

Overwriting a record with another record of the same size is very difficult.

Consider the following function: void reverse( char *string1, const char *string2 ) { int stringsize = sizeof( string1 )/sizeof( char ); *( string1 + stringsize - 1 ) = '\0'; string1 = string1 + stringsize - 2; for ( ; *string2 != '\0'; string1--, string2++ ) *string1 = *string2; }

Pointer/offset notation.

Pointers cannot be used to:

Reference values directly.

Which of the following does the C++ compiler not examine in order to select the proper overloaded function to call?

The return type of the function.

After the ith iteration of the selection sort:

The smallest i items of the array will be sorted into increasing order in the first i elements of the array.

Which of these describe the benefits of using functions?

They allow a programmer to modularize a program They allow reusability - can e used as building blocks in other programs They help eliminate redundant code They make development more manageable; Divide and conquer

Which of the following is not true of pointers to functions?

They can not be assigned to other function pointers.

Comparing pointers and performing pointer arithmetic on them is meaningless unless:

They point to elements of the same array.

Which of the following is not true of static local variables?

They're accessible outside of the function in which they're defined.

The unary scope resolution operator is used:

To access a global variable when a local variable of the same name is in scope.

If the function int volume( int x = 1, int y = 1, int z = 1 ); is called by the expression volume( 3 ), how many default arguments are used?

Two

A variable that can have values only in the range 0 to 65535 is a:

Two-byte unsigned int

When used with ofstream objects, operator! is not:

Used to close a file explicitly.

What are four characteristics of variables?

Value Size Name Type

Arrays as Function Parameters

[] Arrays passed by reference only; Must also pass array size to functions Ampersand (&) not used when declaring array as formal parameter--still passed by reference Base address of array passed as formal parameter ◦ Array name is address of the first element Functions can modify element values Good programming practice: using reserved word const in declaration of array as formal parameter (when needed) ◦ prevents function from altering actual parameter

3 ways to pass arguments to function

[]Pass-by-value Pass-by-reference with reference parameters Pass-by-reference with pointer parameters

Principle of Least Privilege

code should be granted only the amount of privilege and access needed to accomplish its task, but no more.

Which of the following is not a valid enumeration statement?

enum person { me, you, me };

Which of the following will not change the file-position pointer to the same position as the others? Assume a 10-byte file size and a current position at byte # 1.

fileObject.seekg( 8, ios::end );

When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to:

int *a

Which statement would be used to declare a 10-element integer array c?

int c[ 10 ];

Which of the following is not a correct way to initialize an array?

int n[ 5 ] = { 0, 7, 0, 3, 8, 2 };

Which file open mode would be used to write data only to the end of an existing file?

ios::app

What is not true about this code segment?

location is a pointer.

The & operator can be applied to:

lvalues.

Depending on the circumstances, the compiler may ignore the storage class specifier:

register

Which of the following expressions returns the trigonometric sine of x?

sin( x )

Which of the following gives the number of elements in the array int r[ 10 ]?

sizeof r / sizeof ( int )

In the expression

y is the scaling value.

Simple Data Types

◦ Can only store one value at a time ◦ Example of Types: integral (char, short, int, long, and bool) floating (float, double, long double)

Structured Data Types

◦ Each data item is a collection of other data items ◦ Used to group related data of various types for convenient access using the same identifier ◦ user-defined data type (UDT) ◦ Example of Types: array Struct class

C-style string

◦ Implemented as an array of type char that ends with a special character, called the "null character" ◦ The null character has ASCII value of 0 ◦ The null character can be written as a literal in code like: '\0' ◦ Every string literal (i.e. something in double quotes) implicitly contains the null character at the end

Four ways to pass a pointer to a function:

◦ Nonconstant Pointer to Nonconstant Data ◦ Nonconstant Pointer to Constant Data ◦ Constant Pointer to Nonconstant Data ◦ Constant Pointer to Constant Data


Ensembles d'études connexes

Finance 3325 Final Exam Review (Test 2)

View Set

GIVE ME LIBERTY! By Eric Foner Chapter 24

View Set

Unit 2 "Writing and Testing Code", Unit 3 too

View Set

APUSH chapter 13 test multiple choice

View Set

Powerpoint 2019/365 - Concept Review 1

View Set