COP 3223C Final Exam

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

All preprocessor commands begin with what symbol?

#

Match the preprocessor commands to their behavior #elif

#else and #if in one statement

Match the function term to the definition Function Return Type

The data type of the value the function returns

What function is used to open a file?

fopen()

Match the type of loop to the best definition nested loops

one or more loops inside any other while, for, or do...while loop

If you want to pass a single-dimension array as an argument in a function, you would have to declare a formal parameter in one of three ways. Match the definition to the appropriate code example. Formal parameters as an unsized array

void myFunction(int param[]);

When was C first implemented?

1972

Regarding basic data types in C, match the data type to its definition double

A double-precision floating point value

Match the error handling term to its behavior errno

A global variable that indicates an error occurred during any function call

Match the function term to the definition A function

A group of statements that together perform a task

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

Regarding basic data types in C, match the data type to its definition float

A single-precision floating point value

Match the operator to its functionality ==

Checks if two operands are equal

Match the operator to its functionality *

Multiplies two operands

C programming language assumes any non-zero and non-null values as true

True

Match the parts of the program with its definition. ----------------------------------------------------------------- #include <stdio.h> int main() { /* my first program in C */ printf("Hello, World! \n"); return 0; } #include <stdio.h>

preprocessor command

Two enum names cannot have same value

False

enum state {working, failed}; enum result {failed, passed}; If the above enumerations are in the same scope, this source code would compile with no errors

False

Match the error handling term to its behavior stderr

File stream to output all the errors

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

Opens a text file for both reading and writing only

Regarding file opening, one of the arguments that must be passed is the access mode. Match the access mode to its behavior 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

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

Opens a text file for both reading and writing; the reading will start from the beginning but the writing will only be appended

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

Opens a text file for writing

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

Opens a text file for writing in appending mode

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 purposes

Match the preprocessor commands to their behavior #error

Prints error message on stderr

Match the function term to the definition A function definition

Provides the actual body of the function

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

Reads a character

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

Reads a formatted string

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

Reads a string

Match the type of loop to the best definition while loop

Repeats a statement or group of statements while a given condition is true, can execute 0...n times

Match the error handling term to its behavior sterror()

Returns a pointer to the textual representation of the current errno value

Match the preprocessor commands to their behavior #ifdef

Returns true if this macro is defined

Match the preprocessor commands to their behavior #ifndef

Returns true if this macro is not defined

Match the preprocessor commands to their behavior #if

Test if a compile time condition is true

Match the preprocessor commands to their behavior #else

The alternative for #if

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 "MM DD YYYY" format

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. __TIME__

The current time as a character literal in ""HH:MM:SS" format

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. __FILE__

This contains the current filename as a string literal

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. __LINE__

This contains the current line number as a decimal constant

Match the error handling term to its behavior void *malloc(int num);

This function allocates an array of num bytes and leave them uninitialized

Match the error handling term to its behavior void *calloc(int num, int size);

This function allocates an array of num elements of which size in bytes will be size

Match the error handling term to its behavior void *realloc(void *address, int newsize);

This function re-allocates memory extending it up to newsize

Match the error handling term to its behavior void free(void *address);

This function releases a block of memory specified by address

The keyword 'enum' is used to declare new enumeration types in C

True

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

True

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

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

Match the preprocessor commands to their behavior #undef

Undefines a preprocessor macro

Match the preprocessor commands to their behavior #define

Used for constants to increase readability

Match the operator to its functionality &

bitwise AND

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 is source code compiled into?

machine language

What C operator is used to yield the storage size of the object or type in bytes?

sizeof()

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

(type_name) expression

enum day {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; Given the enumeration definition above, what is the value of Sunday?

0

enum day {sunday = 1, monday, tuesday = 5, wednesday, thursday = 10, friday, saturday}; Given the enumeration definition above, what is the value of saturday?

12

Match the loop control statement to the best definition continue

Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating

Match the operator to its functionality >=

Checks if left operand is greater than or equal to right operand

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

Converts a macro parameter into a string constant

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. __STDC__

Defined as 1 when the compiler complies with the ANSI standard

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 erno value

Match the preprocessor commands to their behavior #endif

Ends a preprocessor conditional

Match the function term to the definition main()

Every C program has at least this one function

Match the preprocessor commands to their behavior #include

Inserts a particular header from another file

Match the preprocessor commands to their behavior #pragma

Issues special commands to the compiler

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

It permits two separate tokens in the macro definition to be joined into a single token

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

No errors

A preprocessor command must be the first nonblank character

True

C programming does not provide direct support for error handling

True

Enumeration (or enum) is a user defined data type in C

True

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

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 has functions built in for file access. Match the function to its behavior fputc()

Writes a character value

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

Writes a formatted string

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

Writes a string

There are multiple formats of an acceptable comment in C, select all that apply.

-// comment -/* comment */

What tools are required to set up an environment in order to write, compile, and run a program written in the C language? Select all that apply

-C compiler -Text editor

Why is C widely used? Select all that apply

-Easy to learn -Structured language -It can be compiled on a variety of computer platforms -It can handle low-level activities

A variable definition must include as a minimum which of the following? Select all that apply. int variableName = 53;

-Semi-colon -Data type -Valid name

Which of the following is true regarding a variable in C? Select all that apply.

-has a specific type -the data type determines the set of operations that can be applied to the variable -the data type determines the range of values that can be stored -the data type determines the size of the variable -the data type determines the layout of the variable's memory

Which of the following is branching statement of C language?

-if statement -switch statement -if...else statement

int max(int num1, int num2); Given the function declaration above, which parts of the function comprise the function signature? Select all that apply.

-parameter int num2 -Function name max -parameter int num1

Which of the following is true regarding variable definition in C? Select all that apply.

-provides assurance to the compiler that there exists a variable with the given type and name -has its meaning at the time of compilation only -is useful when you are using multiple files

Which of the following are true regarding arrays. Select all that apply.

-sequential elements -fixed size -same data type

Regarding identifiers for variables, functions, or any other user-defined item, which of the following are acceptable? Select all that apply.

-variable -_variable -VARIABLE -var23iable

What does a storage class define regarding variables?

-visibility -scope -life-time

What is the file extension of a C language source code file?

.c

Given the source code below, how many tokens make up the statement? printf("Hello COP 3223!");

5

Match the operator to its functionality +

Adds two operands

Match the type of loop to the best definition for loop

Allows you to efficiently write a loop that needs to execute a specific number of times; a valid implementation may only include two semicolons

Match the data type to its definition. Basic Types

Arithmetic types and are further classified into integer and floating-point types

Match the data type to its definition. Aggregate Types

Array and structure types

C runs nearly as fast as which other language?

Assembly language

Match the operator to its functionality =

Assigns values from the right side operand to the left side operand

Which language is C the successor of?

B

Match the operator to its functionality !=

Checks if two operands are not equal

Match the operator to its functionality ?=

Conditional expression; If condition is true ? then value X : otherwise value Y

Match the function term to the definition Function Body

Contains a collection of statements that define what the function does

Match the operator to its functionality --

Decrements integer by one

Who developed the C programming language?

Dennis M. Ritchie

Regarding keywords in the C programming language and creating identifiers. Keywords are reserved in all lowercase AND all uppercase.

False

Regarding whitespace in the C programming language, spaces are required between the operators in the following source code in order to compile, run, and provide the correct output. int sum=2+3/2-12*15;

False

Match the operator to its functionality ||

If any of the two operands are non-zero, then the condition becomes true

There are three places where variables can be declared in C programming language. Match the scope to the rule. formal parameters

In the definition of function parameters

There are three places where variables can be declared in C programming language. Match the scope to the rule. local

Inside a function or block

Match the storage class to its definition. static

Instructs the compiler to keep a local variable in existence during the life-time of the program

Match the type of loop to the best definition do...while loop

Is guaranteed to execute at least one time

Match the storage class to its definition. auto

Is the default storage class for all local variables

Match the operator to its functionality /=

It divides the left operand by the right operand and assigns the value to the left operand

Match the operator to its functionality -=

It subtracts the right operand from the left operand and assigns the value to the left operand

Match the data type to its definition. Void

No value is available

There are three places where variables can be declared in C programming language. Match the scope to the rule. global

Outside of all functions

Match the data type to its definition. Derived Types

Pointer, array, structure, union, function types

Match the function term to the definition Parameter list

Refers to the type, order, and number of parameters in the function

Match the operator to its functionality %

Remainder after integer division

Regarding basic data types in C, match the data type to its definition void

Represents the absence of type

Match the operator to its functionality sizeof()

Returns the size of a variable

Match the function term to the definition A function declaration

Tells the compiler about the functions name, return type, and parameters

Match the loop control statement to the best definition break

Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch

Match the function term to the definition Function Name

The actual name of the function

Regarding basic data types in C, match the data type to its definition int

The most natural size of an integer for a machine

Match the storage class to its definition. register

To define local variables that should be stored in register instead of RAM

Match the storage class to its definition. extern

To give a reference of a global variable that is visible to ALL the program files

Match the loop control statement to the best definition goto

Transfers control to the labeled statement

A program can have same name for local and global variables but the value of local variable inside a function will take preference

True

A program stops its execution when break statement is encountered.

True

A specific element in an array is accessed by an index

True

All arrays consist of contiguous memory locations

True

All arrays have 0 as the index of their first element which is also called the base index

True

C programming language assumes any zero or null values as false

True

In a C program, an individual statement must be ended with a semicolon.

True

The scandalous truth is that C has no arrays — that they are merely cleverly disguised pointers

True

To call a function, you simply need to pass the required parameters along with the function name

True

Regarding basic data types in C, match the data type to its definition char

Typically one byte and is an integer type

Match the data type to its definition. Enumerated Types

Used to define variable that can only assign discrete integer values

Match the operator to its functionality !

Used to reverse the logical state of its operand

int a = 30; if( a == 10 ) { printf("Value of a is 10\n" ); } else if( a == 20 ) { printf("Value of a is 20\n" ); } else if( a == 30 ) { printf("Value of a is 30\n" ); } Given the source code above, what would output to the command prompt or terminal window?

Value of a is 30

What punctuation is used to declare the explicit size of an array upon declaration when the array is not initialized during declaration?

[]

If an array is a three-dimensional array, how many sets of square brackets are used to identify each element of the array?

[][][]

int a = 10; if( a < 20 ) { printf("a is less than 20\n" ); } Given the source code above, what would output to the command prompt or terminal as a result of the if condition?

a is less than 20

int a = 30; if( a < 20 ) { printf("a is less than 20\n" ); } else { printf("a is not less than 20\n" ); } Given the source code above, what would output to the command prompt or terminal window?

a is not less than 20

Regarding calling a function, arguments are used when _________ a function

calling

Match the parts of the program with its definition. ----------------------------------------------------------------- #include <stdio.h> int main() { /* my first program in C */ printf("Hello, World! \n"); return 0; } /* my first program in C */

comments

When calling a function, call by value refers to what behavior?

copies the actual value of an argument into the formal parameter of the function

Match the parts of the program with its definition. ----------------------------------------------------------------- #include <stdio.h> int main() { /* my first program in C */ printf("Hello, World! \n"); return 0; } printf("Hello, World! \n");

function available in C

Which of the following is the only methodology to return an array from a function in the C programming language?

int *myFunction()

Given the three situations the void type is used in C, match the associated code with the situation. Function arguments as void

int rand(void);

What type of file contains the source code?

source files

____________ is the built in multiway decision statement in C

switch

Match the parts of the program with its definition. ----------------------------------------------------------------- #include <stdio.h> int main() { /* my first program in C */ printf("Hello, World! \n"); return 0; } return 0;

terminates the main() function

Match the parts of the program with its definition. ----------------------------------------------------------------- #include <stdio.h> int main() { /* my first program in C */ printf("Hello, World! \n"); return 0; } int main()

the main function where the program execution begins

Given the three situations the void type is used in C, match the associated code with the situation. Pointers to void

void *malloc(size_t size);

Given the three situations the void type is used in C, match the associated code with the situation. Function returns as void

void exit(int status);

If you want to pass a single-dimension array as an argument in a function, you would have to declare a formal parameter in one of three ways. Match the definition to the appropriate code example. Formal parameters as a pointer

void myFunction(int *param);

If you want to pass a single-dimension array as an argument in a function, you would have to declare a formal parameter in one of three ways. Match the definition to the appropriate code example. Formal parameters as a sized array

void myFunction(int param[10]);


Kaugnay na mga set ng pag-aaral

Immunologic Agents Drugs Practice Tests

View Set

Fundamentals Practice quiz questions 2

View Set

Multifamily Dwelling Calculations/Advanced NEC Calculations

View Set

Фізіологія дихання ( 1 )

View Set

FN - Chapter 25: Asepsis and Infection Control

View Set

Ch. 40 Respiratory dysfunction pediatric

View Set

AFRICAN AMERICAN HISTORY 2 CHAPTER 13 EXAM

View Set

Baloncesto: Fill in the blanks with basketball scores in Spanish Follow the model.

View Set