#348 Answer these C programming questions
Answer these C programming questions - Computer Science
ChemistryExplain daily providing Q&A content “#348 Answer these C programming questions" in Computer science, Ba computer science, Berkeley computer science, Computer science associate degree jobs
Get the Free Online Chemistry Q&A Questions And Answers with explain. To crack any examinations and Interview tests these Chemistry Questions And Answers are very useful. Here we have uploaded the Free Online Chemistry Questions. Here we are also given the all chemistry topic.
ChemistryExplain team has covered all Topics related to inorganic, organic, physical chemistry, and others So, Prepare these Chemistry Questions and Answers with Explanation Pdf.
For More Chegg Questions
Free Chegg Question
Answer these C programming questions based on its code. (Code of the lines may not be in the right place due to this format)
Line 1: #include
Line 2:
Line 3:
Line 4: int main (int argc, char *argv[])
Line 5: {
Line 6: int i, *p, count = 0;
Line 7: p = &count;
Line 8: for (i = 0; i < 5; i++) {
Line 9: count++;
Line 10: (*p)++;
Line 11: }
Line 12: printf("count = %d, I love money. \n", count);
return 0;
}
From the code above:
a) What is the output of the program and please explain why. (Don't use a compiler but your thought and show the process that came to be your answer)
b) Find the gdb command that makes the breakpoint in line 11.
c) Find the gdb command that shows the value of *p.
d) Compare and contrast step and continue commands. Show how these are interconnected with one another with the breakpoint that you determined in line 11.
For More Chemistry Notes and Helpful Content Subscribe Our YouTube Chanel - Chemistry Explain
Free Chegg Answer
Part a): Output is count=10
- Since p stores address of count variable.
- That means, using (*p) we can access value of count.
- The loop runs 5 times for i = 0 to 4, for each i, count is incremented and (*p) is incremented.
- count is initially 0.
- So, count++ will result in increment of count by 5
- And, (*p)++ will result in increment of count by 5, since (*p) represents count
- So, count=10
Part b): GDB command that makes breakpoint at line 11
- break 11 ,or,
- b 11
Part c): GDB command that shows value of *p
- print *p ,or,
- p *p
Part d): Compare step and continue commands
- Continue: This command resumes the execution from the line where the code was paused by breakpoint. The code keeps on running till the next breakpoint is encountered or till successful execution of complete code.
- Step: This is used to execute only the current line where code is currently paused due to breakpoint. Once this line is executed, the code pauses at the next line.
For example, in the above code, once breakpoint result in pausing of code at line 11.
- If continue is called, code will execute from line 11 and run till the code ends.
- If step is called, line 11 will be executed and code will then pause at line 12.
Screenshot of Debugger:
Labels: Chegg, Free Chegg Answer, Q&A Computer Science
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home