BillHung.Net


powered by FreeFind     sms

Quiz 01

 

Question 1:
Complete the program segment below so that the contents of intPtr and n before return agree with the diagram
intPtr n
+---+ +---+
| *-|--->| 5 |
+---+ +---+


int main ( ) {
int* intPtr;
int n;
intPtr = &n;
n = 5;
return 0;
}




Question 2:
Write a void function named setTo5 that initializes the value of an int variable used in the calling program to 5. Here's a framework for a main program in which setTo5 is used:

#include <stdio.h>

void setTo5 (int* pn);

int main () {
int n = 27;
setTo5 (&n);
printf ("n = %d\n", n); /* should print n = 5 */
return 0;
}

void setTo5 (int* pn){
*pn = 5;
}


Question 3:
What did you find difficult or confusing about the reading? If
nothing was difficult or confusing, tell us what you found most
interesting. In either case, please be as specific as possible.

No, I didn't find anything particular difficult or confusing. The material is pretty straight forward. I don't see anything interseting either, because the material is somewhat standard.

 

 

int main ( ) {
int* intPtr;
int n;
intPtr = &n;
n = 5;
return 0;
}
 

#include <stdio.h>

void setTo5 (int* pn);

int main () {
int n = 27;
setTo5 (&n);
printf ("n = %d\n", n); /* should print n = 5 */
return 0;
}

void setTo5 (int* pn){
*pn = 5;
}