1/77
Flashcards covering key concepts about C programming, GCC, makefiles, and Git commands.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What parameter must you provide to gcc to link in the math library?
-lm (e.g., gcc program.c -lm)
How can you find out the range of possible values for each numeric data type?
Check the limits.h header file (for integer types) and float.h (for floating-point types).
How can you get the value of Pi?
Use M_PI from math.h, or calculate it as acos(-1.0) or 4.0 * atan(1.0).
Does the math library have trigonometric functions?
Yes - sin, cos, tan, etc.
What function should you call before using the rand function?
srand() - to seed the random number generator.
What function checks if a character is alphabetic?
isalpha() from ctype.h.
What function converts a character to uppercase?
toupper() from ctype.h.
How can you convert a string that looks like an integer, to an integer?
atoi() or better: strtol().
How can you convert a string that looks like a real, to a double?
atof() or better: strtod().
What's wrong with the strcpy function?
No bounds checking, it can cause buffer overflows.
What function is better than the strcpy function?
strncpy() or better yet: strlcpy() or strcpy_s().
What function compares strings in alphabetic order, ignoring case?
strcasecmp() or stricmp() on Windows.
What is the strtok function used for?
Tokenizing/splitting strings.
What is the first parameter to strtok the second time you use it?
NULL - to continue tokenizing the same string.
What function searches a string for a character?
strchr() for first occurrence or strrchr() for last occurrence.
What function compiles a regular expression?
regcomp() from regex.h.
Name the three standard IO streams.
stdin, stdout, stderr.
What is the data type of the three standard IO streams?
FILE* (pointer to FILE).
What is the data type of all IO streams?
FILE*.
What's wrong with gets?
No bounds checking - vulnerable to buffer overflows.
What function should be used instead of gets?
fgets().
What is the function to open a file?
fopen().
What does fputs do?
Writes a string to a file stream.
What does fwrite do?
Writes binary data (a block of bytes) to a file.
What function detects a (genuine) end-of-file condition?
feof() - checks the end-of-file indicator.
What function provides random access in a file?
fseek().
What does fflush do?
Flushes the output buffer to the actual file/device.
If you are nervous, what system call should you use after fflush?
fsync() - forces physical write to disk.
What does sprintf do?
formats and writes to a string.
Why did mkstemp replace mktemp?
Security - mktemp had race conditions.
What function is used to get a piece of memory from the heap?
malloc().
What function is used to extend a piece of memory taken from the heap?
realloc().
What function is used to return a piece of memory to the heap?
free().
What is a "memory leak"?
Memory allocated but never freed.
What is a common use for the memset function?
Initializing/zeroing memory blocks.
What function provides an error message for the most recent error in a function call?
strerror(errno) or perror().
What functions provide "time travel" in C?
setjmp() and longjmp().
When does UNIX time start?
January 1, 1970, 00:00:00 UTC.
What function can be used to measure the CPU time used in a program?
clock().
What function installs an "exit handler" in a program?
atexit() - registers a function to be called at normal program termination.
What is the 1st step done by gcc?
Preprocessing.
What is the 2nd step done by gcc?
Compilation.
What is the 3rd step done by gcc?
Assembly.
What is the 4th step done by gcc?
Linking.
What flag stops gcc after the preprocessor?
-E.
What flag stops gcc after producing assembler code?
-S.
What flag stops gcc after producing relocatable binary code?
-c.
What does the -Wall flag do in gcc?
Enables most warning messages.
What does the -O flag do in gcc?
Enables optimization.
What does the -I flag do in gcc?
Adds a directory to the include search path.
What does the -l flag do in gcc? Lowercase L
Links with a library.
What does the -L flag do in gcc?
Adds a directory to the library search path.
What does the -D flag do in gcc?
Defines a preprocessor macro.
What does the preprocessor do with #include lines?
Replaces the line with the contents of the specified file.
What does the preprocessor do with #define lines?
Creates macro definitions.
What does the preprocessor do with #if lines?
Conditional compilation.
What files often contain the interface (declarations) in a C program?
Header files (.h).
What files often contain the implementation?
Source files (.c).
What is the make utility used for?
Automating the build process.
What is a target in a Makefile?
A file to be built or an action to be performed.
What is a dependency in a Makefile?
A file that must exist or be up-to-date before the target can be built.
What is an action in a Makefile?
An action is a shell command executed to build the target.
What character must precede an action?
A TAB character.
What does a clean target usually do in a Makefile?
Removes generated files.
How should non-file targets be identified in a Makefile?
Declared as .PHONY targets.
What are version numbers used for?
Tracking changes and releases over time.
How do revision control systems typically track previous versions of a file?
By storing deltas/diffs.
What is a Github Personal Access Token?
A token/password used for authentication with GitHub.
What does the command git init do?
Initializes a new Git repository.
What does the command git add do?
Stages files for the next commit.
What does the command git commit do?
Records staged changes to the repository.
What does the command git push do?
Uploads local commits to a remote repository.
What does the command git clone do?
Copies a remote repository to your local machine.
What does the command git status do?
Shows the status of working directory and staging area.
What does the command git checkout do?
Switches branches or restores files.
What does the command git tag do?
Creates, lists, or deletes tags.
What does the command git log do?
Shows commit history for the repository.
What is a Github pull request?
A request to merge changes from one branch into another.