C++ Exam 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

When you want to retain the data in a file and add more to the end of it, you should open the file with

"a"

When you want to replace the data in a file, you should open the file with

"w"

the special conversion specifier for printing addresses is ------

%p

The unary * and __________ are complements of one another.

&

the ----, or address operator, is a unary operator that returns the address of its operand.

&

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.

A unit test is

a way of testing a individual function in isolation, without the rest of the program

A character constant is a(n) __________ value represented as a character in single quotes.

int

assume string1 is a character array. which of the following operations does not produce a string?

string1[] = {'t', 'e', 's', 't'};

Function __________ compares up to n characters of its first argument with its second argument.

strncmp

assuming that string1 = "hello" and string2 = "hello world", which of the following returns 0?

strncmp(string1, string2, 5);

Every function of the string handling library except for __________ appends the null character to its result.

strncpy

which of the following does not necessarily append the null character to its result?

strncpy

function fgets appends a ----- to its array target in memory

terminating null character

If an existing file is opened for writing using "w" __________.

the contents of the file are discarded without warning

an expression such as sizeof(arrayName) / sizeof(double) might typically be used to determine

the number of elements in an array

Functions can be listed in one C file and used in another if

the prototypes are listed in a header file included in the other file

What is wrong with this function?void times10(int x) { x *= 10; }

the result of the multiplication is never returned to the caller

When marking a local variable as static

the value remains in memory until the program ends

Which character-handling library function converts lowercase letters to uppercase letters?

toupper

A C structure named product is normally used in code as 'struct product'. To shorten this name to just 'product' you can use

typedef

A function named displayArray takes a 1D int array and an int size variable. Its header could look like which of the following?

void displayArray(int *arr, int size)

memcmp would return ___________ for the callmemcmp("Hi, how are you?", "Hi, how are things?", 6);

zero

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

&t[3]

if bPtr is a pointer to an array named b, then array element b[3] can alternatively be referenced with the pointer expression ----

*(bPtr + 3)

10 three of the following expressions have the same value. which of the following's value is different from the others?

*ptr

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

which statement is false?

A character array representing a string should be defined as large as the actual number of characters in the string minus the terminating character; C automatically provides the space for the terminating character

A static local variable is

All of these are true

A static array is stored in which part of RAM?

Data

Global variables are stored in which part of RAM?

Data

Which of the following is NOT true about a structure in C?

Every element must be the same datatype.

Function fscanf's first argument is of type ________.

FILE pointer

________ are used for permanent retention of large amounts of data.

Files

Which statement is true?

Function fprintf is equivalent to printf except that fprintf also receives as an argument a file pointer for the file to which the data will be written.

Dynamically allocated arrays are stored in which part of RAM?

Heap

Dynamically allocated variables are stored in which part of RAM?

Heap

If an error occurs while opening a file in any mode, function fopen returns ________.

NULL

Which of the following is NOT one of the ways C uses RAM?

Register

Function parameters are stored in which part of RAM?

Stack

which of the following is false?

String literals are written inside of single quotes

Which statement is false?

The unary * operator returns the value of its operand.

which statement is false when dealing with C strings?

When using scanf, you must always precede the string name with the & operator.

When saving an array of values to a file using fprintf, which of the following is true?

You can open the file, write each element one at a time, and then close the file.

In data storage, a field is

a collection of data all related to one type

A stub is

a function that has has the same signature as a function you want to call and acts as a placeholder

In a multi-file program, structs are best defined in

a header file

A function that modifies an array by using pointer arithmetic to process every value should have a parameter that is

a nonconstant pointer to nonconstant data.

A driver is

a piece of code that sends test data to a function to make sure it is behaving as expected

In data storage, a record is

a set of related data about one entity

when the ---- of a variable is passed to a function, the in-direction operator (*) may be used in the function to modify the ---- at that location in the caller's memory

address, value

When calling a function with arguments that should be modified, the __________ of those arguments are passed.

addresses

Pointers may be assigned which of the following?

an address or NULL

Procedural abstraction deals with making functions

as generic and independent of the program as possible PreviousNext

The statement y = &z;

assigns the address of the variable z to pointer variable y.

which statement is false?

call-by- value is always more efficient than call-by-reference

The major difference between malloc and calloc is that

calloc automatically initializes data elements to zero but malloc leaves garbage values in elements until they are initialized

A local static array

can be defined in a function and returned to the calling function

realloc is conventionally used to

change the size of an object previously allocated

The definition char string1[] = "first"; is equivalent to:

char string1[] = {'f', 'i', 'r', 's', 't', '\0'};

In a C structure, the dot operator is used to

connect a structure variable with one of its elements

The least access privilege is granted by a __________ pointer to __________ data.

constant, constant

a non-pointer variable name ---- references a value and a pointer variable name ---- references a value.

directly, indirectly

A function named displayArray takes a 1D int array and an int size variable. A dynamic array named myArray can be passed to this function using the which of the following?

displayArray(myArray, size);

Top-down procedural programming involves everything EXCEPT which of the following?

dividing the code into multiple files

If a pointer to an array is returned from a function and saved in a pointer variable named myArray, how should you access the second element in the array?

either myArray[1] or *(myArray + 1)

strings can not

end in a character other than the null character

Assuming that a file handle named fh has been successfully opened, how should to close it when you are done?

fclose(fh);

Assuming that a pointer to FILE named fh has already been declared, what is the correct way to open the file for writing?

fh = fopen("myfile.txt", "w");

Which statement is true?

fopen returns a pointer to a FILE structure.

A dynamically allocated double variable named num can be deleted from RAM using

free(num);

Assuming a file handle named fh has been declared and the file opened for reading, how should you read in an integer and store it in the int variable num?

fscanf(fh, "%d", &num);

Assuming a file handle named fh has been declared and the file opened for reading, how should you read in an integer and store it in the memory location referenced by the int pointer numPtr?

fscanf(fh, "%d", numPtr);

Function __________ inputs the next character from the standard input and returns it as an integer.

getchar

What is wrong with this code? int x = 0; for (int i = 0; i < 10; i++) x += i; printf("%d %d\n", i, x);

i does not exist after the for loop

referencing a value through a pointer is called -----

indirection

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

int* a

If a local static int array is defined in a function called getArray and is returned to the calling function, what is the correct way to call the function?

int* myArray = getArray();

the functions of the character-handling library typically manipulate characters as -----

ints.

Which character-handling library function returns a true value if its argument is a letter and 0 otherwise?

isalpha

If a static local variable is not initialized when it is declared

it is automatically initialized to zero

If a function defines a static local variable and then returns a pointer to that variable

it will allow the calling function to alter its value

Pointers are variables that contain ----- as their values.

memory addresses

A struct named family has an array of child struct variables named children as an element. A family variable is created named myFam. How would you select the second child?

myFam.children[1]

the highest level of data access is granted by a

non-constant pointer to non-constant data

a function that prints a string should a have a parameter that's a

nonconstant pointer to constant data

When the computer compares two strings, it actually compares the __________ in the strings.

numeric codes of the characters

Before a file can be accessed it must first be

opened

Giving a C structure named product with an element named cost, how would you access the cost of a product variable named p1?

p1.cost

If a struct variable named p1 from a struct named product is already declared an initialized, how would you make a pointer to p1 named p1Ptr?

product* p1Ptr = &p1;

function ---- prints the character equivalent of its integer argument

putchar

Function fscanf is equivalent to function scanf, except that fscanf

receives as an argument a file pointer for the file from which the data is read.

pointers can not be used to

reference values directly

When a structure must be passed to a function, we can use pointers to constant data to get the performance of a call by __________ and the protection of a call by __________.

reference, value

when an array must be passed to a function, we can use pointers to constant data to get the performance of a cal by ---- and the protection of a call by ------

reference, value

To copy all of the elements of one struct variable to another you would use which of the following methods?

s1 = s2;

To pass a struct variable named p1 to a function named setName so that the name element can be set, you would call the function which of the following ways?

setName(&p1);

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

sizeof (r) / sizeof (int)

function strcmp returns ---- if its first argument is equal to its second argument.

specifically 0

If a pointer to a struct variable named sptr is a parameter in a function, the struct element e1 can be accessed using:

sptr->e1


Conjuntos de estudio relacionados

Psychology of adulthood Test 1 (ch1-4)

View Set

Correctly match the organism (genus species) with the disease it causes

View Set

INTRODUCCION AL ANTIGUO TESTAMENTO CLASE #6

View Set

Week 3 Tri-Council Policy Statement: Ethical Conduct for Research Involving Humans (TCPS 2)

View Set