1 #include <stdio.h> 2 #include <cse100.h> 3 4 int complicatedHardCode(DS * data
ID: 3600717 • Letter: 1
Question
1 #include <stdio.h>
2 #include <cse100.h>
3
4 int complicatedHardCode(DS * datastructure) {
5 if (datastructure.isEmpty()) {
6 return 1;
7 }
8
9 return 0;
10 }
11
12 int main(int argc, char ** argv) {
13 DS * datastructure = NULL;
14 char * elementToInsert = NULL;
15 int result = -1;
16
17 if (argc) {
18 elementToInsert= argv[0];
19 }
20
21 datastructure.insert (elementToInsert);
22 result = complicatedHardCode(datastructure);
23 printf("%d ", result);
Answer following question using code above:
1. At some point during debugging, you see the following being printed after you typed in "next":
22 result = complicatedHardCode(datastructure);
What will be printed if you enter "print result?"
2. On the same line, on which line will you be if you enter "next"?
3. Say you are on this line:
5 if (datastructure.isEmpty()) {
What is a command in GDB that brings your debugging INTO the function
`isEmpty()`? (1 point)
Explanation / Answer
1. If "print result" is the given command to gdb, then it will print the value of result, which is
result=-1, so -1 will be printed.
This is because when on command 'next', we see line 22, that line is the next to be executed, that means, it has not executed yet, so till then value in result variable is -1.
2. When we use 'next' command, it just executes the line, it is pointing to and shows the next statement, and yes, it evaluates whole functions if it has to, and it does not enter the definition (code) of the used function.
So, line 23 will be printed if 'next' is used, when on line 22,
printed line is "23 printf("%d ", result);".
3. 'step' is the command used to go into the function (if any). This command works same way as 'next', only difference being, it enters into the definition of any function being used, in the process of evaluating statements.
So, to enter into a function definition, 'step' command is used.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.