Programming Question


1 attachmentsSlide 1 of 1attachment_1attachment_1

Unformatted Attachment Preview

CSCE A201 Midterm #2
This exam is worth a total of 100 points. The exam is open book and open notes. You
can use a calculator or a computer but must do your own work.
I recommend you go through and try to answer all questions directly first and only
type/compile or look up references after attempting all the questions.
Show your work or thought processes. You can insert your answers into this document
and upload your final answers or upload your answers in a separate document(s) that are
compressed into a single zip file.
1) 20 points. Identify the bugs and give a remedy to avoid or fix the bug.
char s[3];
int* foo()
int p;
p = 100;
return &p;
char *p = (char *) malloc(1);
char z;
p = &z;
*p = ‘a’;
char s[100];
if (s == “hi”)
2) 10 points. In the following function prototype the function findMin is given an
array of integers and the number of elements in that array:
int findMin(int arr[], int numElements);
Write the function’s implementation so that it returns the smallest value in the array.
3) 6 points. What generally goes inside a .h file?
4) 6 points. Write the function foo so that after the function is called, the value in
variable n is 100.
int n;
// n should be set to 100 after this call
5) 6 points. Describe an advantage of local variables over global variables.
6) 5 points. Given the array below, after the code runs what value does p point to?
double a[4] = {1.0, 2.0, 3.0, 4.0};
double *p;
p = a;
p = p + 2;
7) 7 points. Give a scenario why you might want to pass a parameter by pointer, even if
the function is only reading from the pointer parameter, not changing any contents of
the pointer.
8) 10 points. The following code sums all the values in an array of length size.
int sum = 0;
for (int i = 0; i < size; i++) sum+=a[i]; Convert the code to a function so that the following function call outputs the sum: printf("The sum is %d.n", computeSum(a, size)); 9) 5 points. Create a struct named Foo so that the following code will run. Make the data type of x an int and y a double. Foo f; f.x = 6; f.y = 3.1; 10) 5 points. Complete the line of code below so that malloc is used to return back the equivalent of an array of 10 integers. int *p = __________________________________ 11) 5 points. What is a breakpoint and what is it good for? 12) 15 points. a) Here is a definition of a struct: typedef struct Stuff { char name[50]; int value; } Stuff; Write code that creates a variable p1 of the struct with the name “foo1” and value 1, and a variable p2 with the name “foo2” and value 2. You can use the string functions. b) Consider this alternate definition of the struct: typedef struct Stuff { char *name; int id; } Stuff; Write code that creates the same variables as part a, except use malloc to allocate the memory for the strings to hold the name. c) If we want to copy one struct to another using assignment like p1 = p2; would this work to make a copy of p2 into p1 if we use the definition in part a? Describe why or why not. What if we use the definition in part b? Describe why or why not. Purchase answer to see full attachment User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Reviews, comments, and love from our customers and community:

Article Writing

Keep doing what you do, I am really impressed by the work done.



PowerPoint Presentation

I am speechless…WoW! Thank you so much!

Stacy V.

Part-time student

Dissertation & Thesis

This was a very well-written paper. Great work fast.

M.H.H. Tony


Annotated Bibliography

I love working with this company. You always go above and beyond and exceed my expectations every time.

Francisca N.


Book Report / Review

I received my order wayyyyyyy sooner than I expected. Couldn’t ask for more.

Mary J.


Essay (Any Type)

On time, perfect paper

Prof. Kate (Ph.D)


Case Study

Awesome! Great papers, and early!

Kaylin Green


Proofreading & Editing

Thank you Dr. Rebecca for editing my essays! She completed my task literally in 3 hours. For sure will work with her again, she is great and follows all instructions

Rebecca L.


Critical Thinking / Review

Extremely thorough summary, understanding and examples found for social science readings, with edits made as needed and on time. Transparent

Arnold W.




Joshua W.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>