C Programming Exam 2

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

When using C's strtol function, the base can be as large as the decimal number ____________.

36

What does the C function getc return if it tries to read a character but finds that it has reached the end of the file?

EOF

The C function fclose closes a file. What does fclose return if it successfully closes the file it has been asked to close?

0

Consider the following declaration and initialization ... const char * x = "Hello" ; The expression * x is a modifiable lvalue.

False

One disadvantage of the buffering of input and output is that buffering decreases the normal data transfer rate.

False

When using the fopen function to open a file, the mode string "a" indicates that the file is being opened for reading.

False

Any variable or array that is declared inside a function and without using the keyword static is of the ______________ storage class

automatic

Which of the following is a C function that not only allocates memory dynamically (i.e., while a program is running), but also sets to zero all the bits in the block of memory that is allocated?

calloc

Which one of the following is not one of the possible scopes of a variable in a C program?

frame scope

In C, the function ________________ takes as its argument an address returned earlier by the malloc function and frees the memory that earlier had been allocated by malloc.

free

In C, variables that have file scope are also sometimes called ________________ variables.

global

C literature uses the term ________________ for such a chunk of memory. Such a chunk of memory can hold one or more values. The chunk of memory might not yet actually have a stored value, but it will be of the right size to hold an appropriate value.

object

In the C programming language, a(n) _____________ is a variable used to store an address.

pointer

Which of the following is a sorting function of the C library?

qsort

In C, a function prototype specifies both the type of value a function returns and the types of arguments it expects. Collectively, this information is called the ______________ of the function.

signiture

The function ________________, whose declaration appears in header file stdio.h, works like the function printf, except that it writes to a string instead of writing to a display.

sprintf

Each C program automatically opens three files. Those file are termed standard input, standard output, and ________________.

standard error output

In C, what is the so-called "generic pointer type?"

void *

Which of the following is the conversion specifier used when printf is used to print an address?

%p

C programs sometimes use several separate files of source code, and sometimes these files might need to share an external variable. In C, the way to do this is to have a "defining declaration" in one file and "referencing declarations" in the other files. All declarations except the "defining declaration" should use the C keyword ________________. Additionally, only the "defining declaration" should be used to initialize the variable.

extern

If your C program - using the fopen function - successfully opens a file, then the fopen function will return a(n) ________________.

file pointer

Which of the following is a C function that is declared in stdio.h that a programmer can use to open a file?

fopen

On a Unix system, the message _________________ indicates a program has attempted to access memory that was not allocated to that program.

"segmentation fault"

C's unary operator ________ yields the address of the variable to which that operator is applied.

&

In C, which of the following is the so-called "null character?"

'\0'

Suppose you have a C program having an array named A that has 10 elements. Which of the following is equivalent to A[5]?

*(A + 5)

A variable having file scope is local to the block containing that variable's declaration. A variable having block scope is known to all functions in a file (or translation unit) following its declaration.

False

If fgets reads a newline character, it discards that newline rather than storing the newline in the string.

False

In C, a variable having internal linkage can be used anywhere in a multifile program, whereas a variable having external linkage can be used anywhere in a single translation unit.

False

In C, if one has a call to a function myFunction(x), then one is transmitting the address of variable x to myFunction. In contrast, if one has a function call myFunction(&x), then one is transmitting the value of variable x to myFunction.

False

In C, it is permissible to use the * operator to add an integer to a pointer.

False

In C, the main function can have two arguments, the first argument being an array of pointers and the second argument being the number of strings in the command line.

False

In a C program, a string literal is enclosed in single quotation marks.

False

In the C programming language, a function is not permitted to call itself.

False

In the C programming language, array members are like ordinary variables in that, if you don't initialize them and they are of the automatic storage class, then they will automatically be given the value 0.

False

Like the function puts, the function fputs automatically appends a newline to the string that it outputs.

False

NULL is the character used to mark the end of a C string. On the other hand, '\0' is a pointer whose value doesn't correspond to a valid address of data.

False

When an executing program terminates, a value may be passed on to the operating systems (for example, passed on to Linux). The usual convention is to pass a value of zero for a program that terminates abnormally, and to pass a nonzero value to indicate normal termination.

False

What does C's fgets function return if that function encounters end-of-file, or if there is some sort of read error?

NULL

Different storage classes offer different combinations of scope, linkage, and storage duration.

True

If a file primarily uses the binary codes for characters (such as ASCII) to represent text, then that file is a text file. On the other hand, if the binary values in a file represent machine-language code or numeric data (using the same internal representation as, for example, that used for double values) or image or music encoding, then the file's content is binary.

True

In C, a variable having block scope normally has automatic storage duration. Such a variable has memory allocated for it when program execution enters the block in which it is defined, and the memory is freed when program execution exits that block.

True

In C, a variable having file scope can have either external linkage or internal linkage.

True

In C, it is permissible to use the + operator to add an integer to a pointer.

True

In C, one cannot pass an entire array as an argument to a function, but instead, one can pass the address of an array as an argument to a function. That function can then use that address to manipulate the original array.

True

In C, the name of an array is also the address of the first element of that array (that is, of the array element having index zero).

True

In C, the two function prototypes shown below are considered equivalent. int f (int * ar, int n) and int f (int ar [], int n)

True

In a C program, the main function can call itself or be called by other functions.

True

In the C Programming language, functions, like variables, have types.

True

In the C programming language, it is possible for a variable to have both block scope and static storage duration.

True

In the standard of the C programming language, the result of using a bad index as a subscript into an array is undefined.

True

Memory for a variable having automatic storage duration is allocated when program execution enters the block containing that variable declaration and is freed when that block is exited.

True

The puts function of C automatically appends a newline to the string it displays.

True

Which of the following is not one of the possible storage durations of an object in a C program?

active storage duration

The C function malloc returns the ________________ of the first byte of the block of memory allocated by that function, or returns a null pointer if the requested block of memory cannot be allocated.

address

If you want to declare an array that's intended to be a read-only array, you should use the keyword _____________ when you declare and initialize that array.

const

In the C programming language, the indirection operator, *, is also called the ______________ operator

dereferencing

Which of the following is a way to determine how many elements are in an array?

divide the size of the entire array by the size of one element

Which one of the following is not one of the possible scopes of a variable in a C program?

division scope

In C, one aspect of an object is its storage ________________, which is how long that object stays in memory.

duration

Memory for dynamically allocated data is taken from a region of memory known as the memory heap, which is also known as the ________________.

free store

In C, an expression that designates an object is called a(n) ________________.

lvalue

Which of the following is a C function that a C programmer may use to allocate memory while a program is running?

malloc

In C, a character string is a char array terminated with a(n) ___________________ character.

null

In C, the ________________ of an identifier describes the region or regions of a program that can access that identifier.

scope

In C, two aspects of an identifier by its linkage and its ________________, which together indicate which parts of a program can use that identifier.

scope

Which of the following is not among the three file pointers that the file stdio.h associates with files automatically opened by C programs?

stdfile

Which of the following is a C function declared in header file string.h that is used for string concatenation?

strcat

Which of the following is a C function declared in head file string.h that compares the contents of two strings (i.e., compares the characters of two strings)?

strcomp

The C programming language provides two ways of accessing a file: binary mode and ________________ mode.

text

The function strncpy provides a safer way to copy a string than does the function strcpy. This is because the function strncpy takes a third argument, which is ________________.

the maximum number of characters to copy

When the fgets function is called, the second argument indicates______________

the maximum number of characters to read

What does the fopen function return if it cannot open the file that it has been asked to open?

the null pointer


Ensembles d'études connexes

Module #3: Collaboration and Teamwork

View Set

Section II - Life Insurance Practice Exam

View Set

Diet and Nutrition Module 2 Chapter 7 Energy Metabolism

View Set

Chapter 1: Introduction to Sociology

View Set

American Literature Proctored Exam

View Set

Business Finance Final Exam (Chapter 5)

View Set

Abdomen/Lower Limb/Etc: Lev Quiz

View Set

Principles of Accounting Module 6

View Set