CS 262

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

If any error occurs, what is returned as a file descriptor?

-1

What is the ouput of the following code snippet? struct point {int x, y;} struct point origin = (0,0); struct point *p = &origin; printf("%s%s\n", *p.x, *p.y);

Error - There is no parentheses around the pointer and '.' operator. (i.e. (p).x && (p).y and order of precedence is violated)

T / F : Once the preprocessor expands all macros and evaluated expressions, all other keywords and identifiers are replaced with the character O.

False (0)

T/F : Structures are allowed to contain instances of itself.

False (They can contain pointers to an instance of itself but not an actual instance)

T/F : The following snippet is correct. char x; read(0, x, 1);

False (need character pointer not, character (i.e. &x))

T/F : Both of the following examples are valid. tar xf <filename.tar> tar -x <filename.tar>

False (need to include the 'f' flag)

T/F : You cannot define a macro without a parameter

False (they are normal macros)

Do you need () or {} for all variables in a Makefile?

For variables with two letters you must use () or {}

What does the .h in #include <string.h> mean?

Header

What does the escape sequence \r mean?

carriage return

what is the code for dynamic memory array allocation of an float array with 5 elements

float * x = malloc(5 * sizeof(float));

What is the output of the following code snippet? int x = 2; switch (x) { case(1): printf("s"); case(2): printf("u"); default: printf("n"); }

un

Which unix command displays memory leak inforamtion?

valgrind ./executable

What does the escape sequence \v mean?

vertical tab

What is the order of precedence for bitwise operators?

~ ,<</>>, &, ^, |

What automatic variable refers to the list of prerequisites including duplicates?

$+

What automatic variable refers to the first prerequisite?

$<

What automatic variable refers to the target name?

$@

What automatic variable refers to the list of prerequisites excluding duplicates?

$^

What are all the conversion characters for long doubles?

%Lf, %Lg, %Le, $La

what format specifier accepts whitespaces for sscanf()?

%[^\n]

What are at the top of the precedence hierarchy? I CAN GUARANTEE THIS IS A TRICK QUESTION ON THE FINAL EXAM! EX: *p->name vs. (*p)->name

'.' , '->' , '()' , '[]'

What does strlen() check for to know when it should stop?

'\0'

Different Directives

- #define = defines a macro - #undef = removes macro definition - #include = insert text from another file - #if = conditionally include text based on constant expression - #ifdef = conditionally include text if macro is defined - #ifndef = opposite of #ifdef - #else = include text if all other conditionalities failed - #endif = terminate conditional text - defined = return 1 if name is defined as a macro, 0 otherwise - #operator = replace macro parameter w/ string constant w/ value - ##operator = create a single token out of two adjacent tokens

What is the output of the following code snippet? char x= 100; x += x; printf("%d\n", x);

-56

what does -lm flag mean?

-l means library -m mean math

which flag is optional when creaiting a tar file

-v

What is the extension of the executable of this code? gcc -E <source_code>

.c

What is the extension of the executable of this code? gcc -c <source_code>

.o

What is the extension of the executable of this code? gcc -S <source_code>

.s

What is the default value of static/external variables?

0

How do you find the two's compliment?

1's compliment and then add 1

what are the 2 ways to declare a string in c

1.) char name[] = "George"; 2.) char name[] = {'G', 'e', 'o', 'r', 'g', 'e', '\0'}; NOTE: brackets can include the number of elements if needed. If int for number of elements is in brackets, that is how much space is allocated in memory for that string. i.e. char name[10] = "George"; takes up 10 bytes in memory

how many bytes are usually needed for a short int

2 contiguous

what is the output of printf("%d,%s", argc, argv[1]) for the command line argument ./greetings 2 !

3, 2

What is the guaranteed minimum value of RAND_MAX?

32767

how many bytes are usually needed for an int

4 contiguous

What is the output of the following code and why? char x = 1345226309; printf("%d\n", x);

69, the 24 MSB are lost and only the last 8 bits remain b/c a char can only hold 1 byte.

how many bytes are reserved for a pointer on zeus?

8

POSSIBLE FINAL QUESTION: What is the output of this code? int x = 0121; (staring 0 means octal) printf("%d\n", x);

81 (1 * 8^2 + 2 * 8^1 + 1 * 8^0)

what is the output of the following code fragment? int a=4, b=10, c; c=a+b/a*2.5; 5 printf("%.1f",(float)c);

9.0

Which characters cannot be included for a variable in a Makefile?

: , = , #

Where are the flag constants defined for open()

<fcntl.h>

Where is the macro BUFSIZ defined?

<stdio.h>

which c library is needed for srand() and rand()

<stdlib.h>

What standard library is needed to include functions of the Unix system and flag constants?

<unistd.h>

Which c library defines the functions read and write?

<unistd.h>

What is the meaning of the following automatic variable? $^

All prerequisites excluding duplicate elements

What is the meaning of the following automatic variable? $+

All prerequisites including duplicates

-v, -version make prints its version and copyright information -h, -help Print make's command-line options -f filename, -file=filename, -makefile=filename (just makefile name) -d Print debugging information -I dir, -include-dir=dir If a makefile contains include directives that specify files without absolute paths, search for such files in the directory dir -B, -always-make make considers all targets out of date (build unconditionally) -C dir, -directory=dir make changes the current working directory to dir before it does anything else. -e, -environment-overrides This command-line option makes environment variables take precedence over variable assignments in makefiles -n, -just-print, -dry-run, -recon make prints the commands, but doesn't actually execute them -i, -ignore-errors Ignore errors -w, -print-directory make prints a line indicating the working directory both before and after processing the makefile

CML OPTIONS

What is the output of the following code snippet? int arr[][2] = { {1, 2}, {3, 4}, {5, 6, 7}}; printf("%d\n", arr[0][0]);

Compilation Error

What does sprintf() do?

Does data formatting and stores the output in a string

How do you establish a buffer for files ?

FILE *fileptr;

T/F : The following is a valid format specifier, %llf?

False

T/F : You can put # with a variable reference or function call in a Makefile.

False

T/F : fgets() when used on file input does not take the whole line

False

What is returned by fopen() if a file cannot be opened?

NULL

what does chmod 554 mean?

Owner - Read, Execute Group - Read, Execute Others - Read

What is a static pattern rule and give an example?

Putting together a target list that utilizes certain characters to derive the prerequisite names from the target names. HINT: Think of it as you are iterating through the target list! EX: a.o b.o c.o: %.o : %.c $(CC) $(CFLAGS)-o $@ -c $^< The result would be the object files all the targets.

What does the format %e mean?

Scientific Notation

What does the -f in regards to make files mean?

Specifies which file contains the rules for the makefile (usually omitted because, by default, looks for a file named Makefile/makefile)

What is the meaning of the following automatic variable? $<

The first prerequisite

What happens if you do not use () for variables with two letters in a Makefile?

The program will only take the first letter and append any others. EX: if C = -Wall then $CC = -WallC

What is the meaning of the following automatic variable? $@

The target filename

T/F : A backslash can be used after the name of a macro to if the value is too long for 1 line.

True

T/F : A target cannot have whitespace to the left of it in a Makefile.

True

T/F : The following code is valid? #include "filename"

True

T/F : This is a valid variable name: int main = 0;

True

T/F : Variables in a Makefile that consist of more than one character must be prefixed with $ and enclosed in either () or {}

True

T/F : fscanf() does not consume the newline

True

T/F : struct {...} x is a valid structure declaration

True

T/F : The following is a valid format specifier, %hhi?

True (char (short, short, int))

T/F : The following is a valid format specifier, %lld?

True (long, long int)

What is the output of the following code snippet? int myArray[2][3] = { { 1, 2, 3} , { 4, 5 , 6} }; printf("%d\n", *(myArray + 1));

Unknown

When should you use #include "filename" vs #include <filename>

Use "" when you are including source files specific to your own programs. Use <> when you are including standard c header files or additional header files provided. by implementation

How do you continue a comment across multiple lines in a Makefile?

\ (Not escaped)

what is the default executable file name?

a.out

What is the third step in the creation of the executable? What is the corresponding flag to stop there?

assembly (machine or object code), -c flag

What does the escape sequence \a mean?

bell character

what does -Wall flag mean?

compiler warnings

What is the second step in the creation of the executable? What is the corresponding flag to stop there?

compiliation (assembly code), -S flag

what does -g flag mean?

debugging information

Pointers and structures are ____________ types.

derived

What happens when you use fopen(*exisiting file*, w) ?

existing file is deleted, new one takes its place

How do you close a file?

fclose(fileptr);

What does the escape sequence \f mean?

formfeed

What unix command(s) shows you more information about gcc?

gcc --help man gcc (NOT gcc man)

Explain what the following code snippet does: ++pointer -> member

increases the value of the member

What is the fourth step in the creation of the executable? What is the corresponding flag to stop there?

linking (final executable), -o to have <executable_name>.out

Fortmatting Ouput

minus sign = left adjustment number before decimal = min width number after decimal = max characters

What happens when you use fopen(*non-existing file*, a) ?

new file is created

What is the shorthand for accessing a structures members with a pointer?

pointer (to structure) -> member

What is the first step in the creation of the executable? What is the corresponding flag to stop there?

preprocess (all comments/directives removed), -E flag

How would you print 3 without using brackets (i.e. [][]) ? int myArray[2][3] = { { 1, 2, 3} , { 4, 5 , 6} };

printf("%d\n", *(*(myArray) + 2));

What do the following FileType specifications of the fopen() function indicate? r w a r+ w+ a+

r = opening existing file for reading only w = opening new file for writing only a = opening existing file for appending r+ = opening existing file for update (reading and writing, also discards any previous content) w+ = opening new file for update (discard previous contents, if any) a+ = opening existing file for update, writing at end

What is the h conversion character?

short integer

if srand() is not called, what will srand() be when rand() is called?

srand(1)

What library contains the malloc() function?

stdlib

what command allows you to view the contents of a tar file

tar tvf <filename.tar>


Set pelajaran terkait

speech and communication chapter 1-5

View Set

Chapter 40: Management of Patients with Gastric and Duodenal Disorders

View Set

ТАБЛИЦА СЛОВООБРАЗОВАНИЯ (Q)

View Set

NUTR 132 Introductory Nutrition (CSULB) EXAM 1

View Set

Human Services and Counseling Exit Exam LWC

View Set

Massachusetts RMV Permit Test Part 1

View Set

Relationships, foreign investment, and trade

View Set