COP3223C Final

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

All preprocessor commands begin with what symbol? ***********

#

Which C preprocessor offers: Converts a macro parameter into a string constant. ***********

#

Which C preprocessor offers: It permits two separate tokens in the macro definition to be joined into a single token. ***********

##

Used for constants to increase readability ***********

#define

#else and #if in one statement ***********

#elif

The alternative for #if ***********

#else

Ends preprocessor conditional. ***********

#endif

Prints error message on stderr ***********

#error

Tests if a compile time condition is true. ***********

#if

Returns true if this macro is defined ***********

#ifdef

Returns true if this macro is not defined ***********

#ifndef

Inserts a particular header from another file. ***********

#include

What are the 2 forms that are used when including syntax? #include...

#include <stdilb.h> #include "header.h" (your own file)

Issues special commands to the compiler ***********

#pragma

Undefines a preprocessor macro ***********

#undef

Which of the following is an example of using the cast operator? *********** - expression as (type_name) - expression (type_name) - type_name expression - (type_name) expression

(type_name) expression

Is the last argument

*argv[n]

Which C preprocessor offers: A macro is normally confined to a single line, however, when multiple lines are required use this operator. ***********

/

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

Can convert the values from one type to another (type_name) expression.

Cast Operator

Many times they are important for your program especially when you want to control your program from outside instead of hard coding those values inside the code.

Command Line Arguments

Instead the preprocessor offers the ability to use a macro for the header name.

Computed Include

To iterate over all the members of the linked list, this pointer is used.

Current

How would you remove a specific item from a list? (Linked List)

Either by its index from the beginning of the list or by its value.

A user defined data type in C. ********************** Mainly used to assign names in integral constants, the names make a program easy to read and maintain.

Enumeration

T/F *********** Two enum names cannot have same value

False Two enum names can have same value

T/F Command Line Arguments If no arguments are supplied, argc will be 2 If one argument is supplied, argc will be 1

False, If no arguments are supplied, argc will be 1 If one argument is supplied, argc is set at 2

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, there are errors.

T/F When doing a linked list you can continue to code until the next variable will be a specific value.

False, until it will be a NULL. EX: node_t * head = NULL; head = malloc(sizeof(node_t)); head->val = 1; head->next = malloc(sizeof(node_t)); head->next->val = 2; head->next->next = NULL; //can end here bc of the NULL

Header Files

Files in which you can declare your own functions that you can use in your main program or these can be used while writing large C programs.

A set of dynamically allocated nodes, arranged in such a way that each node contains one value and one pointer.

Linked List

Which of these does a Header File NOT contain? Definitions of data types Function Prototypes Loops C preprocessor commands

Loops

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

No errors

How would we be able to modify the head variable in a linked list?

Pass a pointer to the pointer variable (a pointer to a pointer) so we will be able to modify the pointer itself.

What is the purpose of the stdarg.h header file?

Provides the functions and macros to implement the functionality of variable arguments.

The process of repeating items in a self-similar way. Calls itself.

Recursion

What does this algorithm do? -Iterate to the node before the node we wish to delete -Save the node we wish to delte in a temporary pointer -Set the previous node's next pointer to point to the node after the node we wish to delete -Delete the node using the temporary pointer.

Removing a specific item in a linked list.

What happens if the header file is included twice?

The compiler will process its constents twice and it will result in an error.

What is va_arg macro and va_list variable used for?

To access each item in argument list.

Is this considered a linked node code? typedef struct node { int val; struct node * next; }

True

T/F In a linked list the pointer always points to the next member of the list.

True

T/F Program Exit Status EXIT_SUCCESS is a macro and is define as 0. If there is an error condition in your program. EXIT_FAILURE is defined as -1.

True

T/F You can pass all the command line arguments separated by a space. If an argument has a space, pass such arguments by putting them inside double quotes "" or single quotes ''

True

T/F *********** 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

T/F It is possible to pass some values from the command line to your C programs when they are executed

True

T/F *********** A preprocessor command must be the first nonblank character

True

T/F *********** C programming does not provide direct support for error handling

True

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

True

T/F *********** The C Preprocessor is not part of the compiler, but is a separate step in the compilation process.

True

T/F *********** The keyword 'enum' is used to declare new enumeration types in C.

True

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

True

T/F *********** Type casting is a way to convert a variable from one data type to another data type.

True

T/F While programming, if you are aware of the size of an array then it is easy and you can define it as an array.

True EX: max of 100 characters. Defined as char name[100];

a way to convert a variable from one data type to another data type.

Type Casting

Implicitly performed to cast their values to a common type.

Usual Arithmetic Conversions

Is it possible to create your own header file?

Yes

How would you remove the first item (popping from the list)

You would need to reverse this action: -Take the next item that the head points to and save it. -Free the head item. -Set the head to be the next item that we've stored on the side.

The current data as a character literal in "MMM DD YYYY" ***********

__DATE__

This contains the filename as a strong literal ***********

__FILE__

This contains the current line number as a decimal constant. ***********

__LINE__

Defined as 1 when the complier compiles with the ANSI standard. ***********

__STDC__

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

__TIME__

Opens a text file for writing in appending mode. ***********

a

When doing a linked list you should always check if malloc returned .....

a NULL value or not.

The command line arguments are handled using main() function arguments where argv[ ] is...

a pointer array which points to each argument passed to the program.

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

a+

Holds the name of the program itself

argv[0]

A pointer to the first command line argument supplied

argv[1]

So you have complete control and you can pass any size value while allocating memory, unlike arrays where once the size defined, you cannot change it.

calloc( ); EX: calloc(200, sizeof(char));

A global variable and indicates an error occurred during any function call. ***********

errno

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( )

Reads a character ***********

fgetc( )

Reads a string ***********

fgets( )

What function is used to open a file? ***********

fopen( )

Writes a formatted string ***********

fprintf( )

Writes a character value. ***********

fputc( )

Writes a string ***********

fputs( )

When you are not in need of memory anymore then you should release that memory by calling the function ...

free ( )

Reads a formatted string ***********

fscanf( )

Displays the string you pass to it, followed by a colon, a space, and then the textual representation of the current errno value. ***********

perror( )

Opens an existing text file for reading purposes ***********

r

Opens a text file for both reading and writing only. ***********

r+

You can increase or decrease the size of an allocated memory block by calling the function .....

realloc( )

What are the best use cases for linked lists?

stacks and queues

File stream to output all the errors. ***********

stderr

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

strerror( )

The command line arguments are handled using main() function arguments where argc refers to....

the number of arguments passed.

What is a macro va_end used for in va_list?

va_end is used to clean up the memory assigned to va_list variable.

This fuction allocates an array of num elements each of which size in bytes will be size. ***********

void *calloc(int num, int size);

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

void *malloc(int num);

This function re-allocates memory extending it upto newsize. ***********

void *realloc(void *address, int newsize);

This function releases a block of memory block specified by address. ***********

void free(void *address);

Opens a text tile for writing. ***********

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

w+


Kaugnay na mga set ng pag-aaral

CSC251-N811 Exam2 Study Guide Chp7

View Set

Health: Developing Muscular Strength and Endurance

View Set

Communications Chapter 2 Vocabulary

View Set

Surveys, Samples, Experiments, Data Displays, Descriptive Statistics

View Set

Gran Maestros de la Pintura: Picasso

View Set

A&P 1- Chapter 4 - Tissue Level of Organization

View Set

Unit 1: Foundations of American Democracy

View Set

Section 6: Closing, Possession, and More in Texas Contracts

View Set

Pharmacoeconomics Chapter 5 Practice Questions

View Set