COP 3223C Exam 3 Karin Whiting

Ace your homework & exams now with Quizwiz!

What does function scanf() require as a first argument to receive data from stdin?

"char *format"

All preprocessor commands begin with what symbol?

#

Match the preprocessor commands to their behavior.

#define Used for constants to increase readability #include Inserts a particular header from another file #undef Undefines a preprocessor macro #ifdef Returns true if this macro is defined #ifndef Returns true if this macro is not defined #if Tests if a compile time condition is true #else The alternative for #if #elif #else and #if in one statement #endif Ends preprocessor conditional #error Prints error message on stderr #pragma Issues special commands to the compiler

What special character is used in C to denote the memory address of a variable?

&

Which of the following is an example of using the cast operator?

(type_name) expression

What notation is used to dereference a pointer?

*

What special character is used when declaring a variable that is a pointer?

*

1 typedef struct human 2 { 3 char name[20]; 4 GameBoard gameBoard; 5 Ship ships[NUM_SHIPS]; 6 } Player; 7 Player playerOne; 8 initializePlayer(&playerOne, PLAYERONE); 9 void initializeBoard(Player * player) 10 { 11 player?gameBoard; 12 } Given the source code above, referencing the ? at line 11, which of the following is the correct punctuation or notation to access member gameBoard in parameter player?

->

1 typedef struct location 2 { 3 int row; 4 int column; 5 } Location; 6 Location loc; 7 loc?row = 5; 8 loc?column = 5; Given the source code above, referencing the ?'s on line 7 and 8, what is the correct notation to access row and column of struct Location variable loc?

.

When accessing union members, what punctuation or notation is used?

.

Given the code example below, what is the maximum value that can be stored in bit field age? struct { unsigned int age : 4; } Age;

15

Given the source code below, how much memory is allocated to bit fields widthValidated and heightValidated each? struct { unsigned int widthValidated : 1; unsigned int heightValidated : 1; } status2;

2 bits

union Data { int i; float f; char str[20]; }; Given the inherent behavior of unions and the source code union definition above, how much memory will be allocated for a variable of data type union Data?

20 bytes

What is the basic behavior of recursion in software programming?

A function that calls itself

Given the source code below, how should a developer declare a variable of struct BookTwo? Select all that apply. typedef struct BookTwo { char title[50]; char author[50]; char subject[100]; int book_id; } BOOK;

BOOK aBook; struct BookTwo aBook;

A recursive function is identical to looping behavior.

False

The data type of a pointer does not need to match the data type of the variable it points to.

False

If errno is the value of 0, what does it indicates regarding the status of the program?

No errors

How many union members can contain a value at a given time?

One

1 typedef struct human 2 { 3 char name[20]; 4 GameBoard gameBoard; 5 Ship ships[NUM_SHIPS]; 6 } Player; 7 Player playerOne; 8 initializePlayer(&playerOne, PLAYERONE); Given the source code above, line 8 is which type of an example regarding pointers?

Passing a pointer to a function

A preprocessor command must be the first nonblank character.

True

C programming does not provide direct support for error handling

True

C programming keyword typedef allows software developers to give an existing data type a new name.

True

Command line arguments are values passed to the executable during run time from the command line.

True

If no arguments are passed to an executable with the function signature int main( int argc, char *argv[] ), argc will be the value of 1.

True

It is considered good programming practice to use the cast operator whenever type conversions are necessary

True

Recursion is defined as a program that allows a programmer to call a function inside the same function.

True

The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process

True

The C programming language allows programmers to define a function which can accept variable number of parameters.

True

The usual arithmetic conversions are not performed for the assignment operators, nor for the logical operators && and ||

True

To support using variable argument functionality, need to include the stdarg.h header file.

True

Type casting is a way to convert a variable from one data type to another data type

True

When passing command line arguments to an executable, arguments that include a space should be inside double quotes "" or single quotes ''.

True

When passing command line arguments to an executable, the arguments should be separated by a space.

True

typedef interpretation is performed by the compiler.

True

typedef is limited to giving symbolic names to types only.

True

void integerPromotion() { int i = 17; char c = 'c'; int sum; sum = i + c; printf("Value of sum : %d\n", sum ); } Given the C data types and the concept of integer promotion, the above source code would compile and run without errors.

True

The C preprocessor offers operators to help create macros. Match the operator to its behavior.

\ A macro is normally confined to a single line, however when multiple lines are required use this operator # converts a macro parameter into a string constant ## It permits two separate tokens in the macro definition to be joined into a single token

The C Programming language includes predefined macros. They are available for use in programming however, the predefined macros should not be directly modified. Match the predefined macro to its behavior.

__DATE__ The current date as a character literal in "MMM DD YYYY" format __TIME__ The current time as a character literal in "HH:MM:SS" format __FILE__ This contains the current filename as a string literal __LINE__ This contains the current line number as a decimal constant __STDC__ Defined as 1 when the compiler complies with the ANSI standard

Which of the following best defines a pointer in C?

a variable whose value is the address of another variable

What is unique about the data type union?

allows to store different data types in the same memory location

What is critical for recursion to avoid an infinite loop?

an exit condition

What is the condition where a recursive function will not continue to call itself so it can stop recusing?

base case

What is the term associated with variables defined with a predefined width?

bit fields

What is the global variable that indicates an error occurred during any function call defined in <error.h> header file?

errno

What function is used to close a file?

fclose()

What function is used to open a file?

fopen()

The C Programming language has functions built in for file access. Match the function to its behavior.

fputc() - writes a character value fputs() - writes a string fprintf() - writes a formatted string fgetc() - reads a character fgets() - reads a string fscanf() - reads a formatted string

Given the source code below, match the term to its purpose. int main( int argc, char *argv[] ) { printf ("arg 0 = %s\n", argv[0]); if( argc == 2 ) { printf("The argument supplied is %s\n", argv[1]); } else if( argc > 2 ) { printf("Too many arguments supplied.\n"); } else { printf("One argument expected.\n"); } }

function parameter "int argc" - refers to the number of arguments passed function parameter "char *argv[]" - a pointer array which points to each argument passed to the program array element argv[0] - holds the name of the program array element argv[1] - a pointer to the first command line argument supplied

Given the source code below, match the terms to their purpose in variable arguements. double average(int num, ...) { va_list valist; double sum = 0.0; int i; /* initialize valist for num number of arguments */ va_start(valist, num); /* access all the arguments assigned to valist */ for (i = 0; i < num; i++) { sum += va_arg(valist, int); } /* clean memory reserved for valist */ va_end(valist); return sum/num; }

function parameter "int num" - represent the total number variable arguments passed function parameter "..." - variable argument list va_arg - access each item in argument list va_list - variable to store the variable argument list received as "..." va_start - initializes va_list for the number of arguments va_end - clean up the memory assigned to va_list variable

typedef struct gameboard { char board[ROWS][COLS]; } GameBoard; GameBoard gameBoard; Given the source code above, which of the following code examples is the correct methodology to pass struct GameBoard variable gameBoard to a function as a pointer?

initializeGameBoard(&gameBoard);

typedef struct gameboard { char board[ROWS][COLS]; } GameBoard; GameBoard gameBoard; Given the source code above, which of the following code examples is the correct methodology to pass struct GameBoard variable gameBoard to a function as a struct?

initializeGameBoard(gameBoard);

typedef struct location { int row; int column; } Location; Given the source code above, what are the variables row and column called in a struct?

members

How many characters does function getchar() read?

one

How many characters does function putchar() output at a time?

one

Match the error handling term to its behavior.

perror() - displays the string you pass to it, followed by a colon, a space, and then the textual representation of the current errno value strerror() - returns a pointer to the textual representation of the current errno value errno - a global variable and indicates an error occurred during any function call stderr - file stream to output all the errors

Placeholder

placeholder

Regarding file opening, one of the arguments that must be passed is the access mode. Match the access mode to its behavior.

r - Opens an existing text file for reading purpose w - Opens a text file for writing a - Opens a text file for writing in appending mode. r+ - Opens a text file for both reading and writing only w+ - Opens a text file for both reading and writing; it first truncates the file to zero length if it exists, otherwise creates a file if it does not exist. a+ - Opens a text file for both reading and writing; The reading will start from the beginning but writing can only be appended

In recursion, function calls are put on a _________.

stack

Regarding standard files in the C programming language, which of the following is used for standard error?

stderr

Regarding standard files in the C programming language, which of the following is used for standard input?

stdin

Regarding standard files in the C programming language, which of the following is used for standard output?

stdout

1 union Data 2 { 3 int i; 4 float f; 5 char str[20]; 6 }; 7 union Data data; 8 data.i = 10; 9 data.f = 220.5; 10 strcpy( data.str, "C Programming"); Given the source code above and the inherent behavior of unions, which union member will have a value stored at the memory address of union Data variable data?

str

What C programming keyword is used to define a structure?

struct

What C programming keyword is used to define a union?

union

Given the source code below, match the term to the components of the struct definition. struct { unsigned int age : 3; } Age;

unsigned int - data type of bit field age - name of the bit field 3 - size of the bit field in bits Age - variable of the bit field struct

Regarding memory management, match the function to the best definition.

void *calloc(int num, int size); - This function allocates an array of num elements each of which size in bytes will be size void free(void *address); - This function releases a block of memory block specified by address void *malloc(int num); - This function allocates an array of num bytes and leave them uninitialized void *realloc(void *address, int newsize); - This function re-allocates memory extending it upto newsize


Related study sets

The Enlightenment in England (Modern Humanities)

View Set

Principals of Management study #2

View Set

Cell membrane Controls what comes into and out of a cell

View Set

Chapter 22: Management of Patients with Upper Respiratory Tract Disorders

View Set

Penny Chapter 26: Fetal Spine and Musculoskeletal System Review Questions

View Set

overview of the nursing process (potter)

View Set

MUSCULO-SKELETAL SYSTEM- LONG BONE: STRUCTURES AND FUNCTIONS

View Set