CS2505 Exam 1

Ace your homework & exams now with Quizwiz!

What are the common format strings, e.g. for integers, strings, characters?

%d: for integers %f: for floating-point numbers %c: for characters %s: for strings

What options do we normally use?

-o outputfile: to specify the output file name -Wall: to enable all warnings -Werror: to treat warnings as errors -std=c99 or -std=c11: to specify the C standard to use

What is the purpose of a Bash script?

A Bash script is a file containing a series of commands and statements in the Bash shell language. The purpose of a Bash script is to automate tasks and simplify complex or repetitive tasks that would otherwise need to be done manually.

What is the purpose of a Makefile?

A Makefile is a file containing a set of rules for building and compiling a software project. The purpose of a Makefile is to automate the build process and ensure that all the source files are compiled and linked correctly.

What are the parts of a Makefile?

A Makefile typically consists of several parts: Variables: used to store values, paths, and flags that are used throughout the Makefile Targets: the output files that we want to build, such as executable files, object files, or libraries Dependencies: the source files that are needed to build each target Rules: specify how to build each target, and what dependencies to use Phony targets: targets that don't correspond to actual files, but are used for running commands or sub-makefiles.

A high-level understanding of what a pointer is

A pointer is a variable that holds the memory address of another variable. Pointers allow us to indirectly access and manipulate the data stored in memory.

How to access and work with an array in C (hint: it is very similar to Java)

In C, arrays are a sequence of elements of the same data type. To access an element in an array, we use its index, which starts at 0. Arrays can be accessed and manipulated using loops, pointers, and array arithmetic. Array syntax is similar to Java: array[index] = value;, for(int i = 0; i < size; i++) { ... }.

How "multiple return" works

In C, functions can return only one value, but we can simulate multiple return values by using pointers. The function can take pointers as arguments, and then modify those pointers to return the values.

How passing pointers into a function works

Passing pointers into a function allows the function to modify the original variable passed in by the caller. When a pointer to a variable is passed into a function, the function can use the pointer to access and modify the original variable.

What are the basic steps in compiling and linking?

Preprocessing: the preprocessor replaces macros and includes header files. Compilation: the compiler converts the preprocessed source code into assembly code. Assembly: the assembler converts the assembly code into object code. Linking: the linker combines the object code with libraries to create an executable file.

What are the basic navigational commands in GDB?

Some basic navigational commands in GDB include: break or b: sets a breakpoint at a specified line or function run or r: runs the program until a breakpoint or error occurs next or n: executes the next line of code (skips over function calls) step or s: executes the next line of code (steps into function calls) print or p: prints the value of a variable or expression backtrace or bt: prints the stack trace of the current execution context

What are the arguments to main?

The arguments to main are argc and argv, which represent the number of command-line arguments and an array of strings containing the arguments, respectively.

What is the default passing mechanism for parameters for functions?

The default passing mechanism for parameters in C is pass-by-value.

What is the general definition of lifetime for a variable?

The lifetime of a variable is the period during program execution when the variable exists in memory and can be accessed. It begins when the variable is created and ends when the variable is destroyed. The lifetime of a variable is determined by its storage class.

What are the rules for naming an identifier?

The rules for naming an identifier in C are: It must begin with a letter (uppercase or lowercase) or underscore character (_). The rest of the characters can be letters, digits, or underscore characters. It must not be a reserved keyword.

What is the general definition of scope for a variable?

The scope of a variable is the region of the program where the variable can be accessed. It is determined by the location of the variable declaration.

How do we run GDB?

To run GDB, we need to compile our program with debugging symbols enabled (-g flag), and then run GDB on the executable file. We can run GDB using the following command: gdb program.

How can we write Makefiles?

To write a Makefile, we need to specify the dependencies between the source files and the targets (i.e., the compiled output files). We can use variables to store common values and paths, and we can define rules that specify how to build each target. We also need to specify the dependencies between the source files and the targets, so that Make knows which files need to be rebuilt when a source file changes.

How can we write basic Bash scripts?

To write a basic Bash script, we need to create a file with a .sh extension, and then add the commands we want to run in the script. We need to make the script file executable using the chmod command, and then we can run the script using ./script.sh. We can also use variables, loops, and conditionals in our Bash scripts to make them more powerful and flexible.

Is a given identifier name valid? dave, _dave, 3dave, d&ve, s3nger, senger!

Valid: dave, _dave, s3nger, senger Invalid: 3dave, d&ve (identifiers cannot begin with a digit or contain special characters except for underscore)

How do we use header files to declare functions? What is the difference between #include with "" vs. <>?

We use the #include directive to include header files that declare functions. The difference between #include with "" and #include with <> is that the former searches for the header file in the current directory and then in the standard system directories, while the latter searches only in the standard system directories.

How do we view the stack trace when our program crashes in GDB?

When a program crashes in GDB, we can use the backtrace or bt command to view the stack trace. The stack trace shows the sequence of function calls that led to the crash, and can help us identify the source of the problem. We can also use the frame or f command to switch between frames in the stack trace and view the values of local variables at each level

If a function needs to modify a parameter, and you want the caller to "know" about the change, what do you add to the parameter to allow for this?

You add a pointer to the parameter to allow the function to modify the original variable.

When you call a function that uses pass-by-pointer, what is the easiest way to provide the pointer the function needs? e.g. int x; function f(int *x); f(???);

You can pass the address of the variable by using the "&" operator. For example: f(&x);

How can you add the debugging symbols?

You can use the -g option to include debugging symbols in the executable file, which can be used with a debugger to aid in debugging.

If you want to open a file for input, how do you do that?

You can use the fopen() function with the appropriate file mode, such as "r" for reading.

If you want to open a file for output, how do you do that?

You can use the fopen() function with the appropriate file mode, such as "w" for writing. If you want to append to an existing file, you can use "a" instead.

What do you have to do first so you can use a function?

You have to declare or define the function before you can use it.

What does that most basic command call the output file?

a.out

What is the most basic command to compile?

gcc

What are the basic control structures in C?

if statement while loop for loop switch statement do-while loop

What are the primitive types in C?

int char float double short long long long _Bool

What are their typical sizes in bytes?

int: 2 or 4 bytes char: 1 byte float: 4 bytes double: 8 bytes short: 2 bytes long: 4 or 8 bytes long long: 8 bytes _Bool: 1 byte

What is the basic command to output data?

printf()

What is the basic command to read in data?

scanf()

What is the name for keyboard input?

stdin

What are the names for output to the terminal?

stdout & stderr

What is the intended difference of stdout & stderr?

stdout is used for regular output, while stderr is used for error messages and other diagnostics.


Related study sets

(UCSP) Unity In Diversity - Culture

View Set