Lecture20-Homework-pointers.pdf - COMP.1010 Homework Pointer F19 Dr Lin Due date Oct 25 2019(F BEFORE the class starts Name Section_10am_11am You must

Lecture20-Homework-pointers.pdf - COMP.1010 Homework...

• 2

This preview shows page 1 - 2 out of 2 pages.

COMP.1010 Homework, Pointer, 10-21-2019 F19 - Dr. Lin Due date : Oct. 25, 2019 (F), BEFORE the class starts Name : _______________________________________ Section: ______10am_________11am_________ You must Run the following C code and get the run-time values from your computer memory to answer questions 2~4. You may type the code in zyBook section 9.4; add printf with %p if needed to observe the values. #include <stdio.h> int main( int argc, char * argv[]) { int *p1, *p2, *p, a, b; printf ( "Please enter two integers: " ); scanf ( "%d,%d" , &a, &b); //enter two integers //separated by a comma ‘,’ p1 = &a; p2 = &b; if (a < b) { p = p1; p1 = p2; p2 = p; } printf ( "a=%d, b=%d\n" , a, b); printf ( "max=%d, min=%d\n" , *p1, *p2); return 0 ; } 1. What is a pointer in C? Which variables in this program are pointer variables? 2. What are the values of expression p1, p2, &a, and &b in your computer before the

You've reached the end of your free preview.

Unformatted text preview: if statement executes? (Add printf or use breakpoints to check the run-time variable values) p1 _________________________ p2 _________________________ &amp;a _________________________ &amp;b _________________________ COMP.1010 Homework, Pointer, 10-21-2019 F19 - Dr. Lin 3. What are the values of p1, p2, p in your computer after if statement executes and before the printf statements execute? (You may add printf or use breakpoints to check the values) p1 _________________________ p2 _________________________ p ___________________________ 4. What does this program do? Draw graph(s) (the ones we use in class) to support your description. 5. Were the values of a and b changed in program execution? What are changed? 6. What is the purpose to use the pointer p?...
View Full Document

• Fall '15

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern