49 lines
No EOL
1.9 KiB
Text
49 lines
No EOL
1.9 KiB
Text
1. What is the difference between a declaration and a definition?
|
||
|
||
A declaration tells the compiler about the existence of a variable or function,
|
||
while a definition allocates storage or provides the function code.
|
||
|
||
|
||
2. How does an include guard prevent multiple definitions?
|
||
|
||
An include guard (using #ifndef, #define, #endif)
|
||
prevents a header file from being included multiple times, which avoids redefinitions.
|
||
|
||
|
||
3. How can you tell if an error comes from the compiler or the linker? Does a linker error
|
||
mean that you have an error in your source code? How do you (typically) fix a linker error?
|
||
|
||
Compiler errors are syntax or semantic issues in code, while linker errors occur when symbols
|
||
are missing or duplicated across files. A linker error often means a missing definition or library; it’s fixed by ensuring all functions and variables are correctly defined and linked.
|
||
|
||
|
||
4. Do you have to make any changes to MakefileWithDeps to build your hello world program?
|
||
|
||
You may need to adjust MakefileWithDeps
|
||
if dependencies or file paths change for your hello world program.
|
||
|
||
|
||
5. In encode and decode, the type unsigned char is used. Would your code work the same
|
||
way if that type is changed to char or signed char?
|
||
|
||
Changing unsigned char to char or signed char
|
||
may alter the behavior due to differences in handling negative values.
|
||
|
||
|
||
6. In the coding problem, reading the file with char ch; while (infile >> ch) ... doesn’t
|
||
work. Why?
|
||
|
||
infile >> ch reads formatted input, skipping whitespace;
|
||
using infile.get(ch) reads every character, including whitespace.
|
||
|
||
|
||
7. If your program crashes, how can you use the debugger to get a stack trace similar to that
|
||
of Exception.printStackTrace() in Java?
|
||
|
||
lldb ./progrma -> run -> bt
|
||
|
||
|
||
8. What is the difference between a debugger breakpoint and a watchpoint?
|
||
|
||
A breakpoint pauses execution at a specific line,
|
||
while a watchpoint stops execution when a specific variable changes. |