• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 9 pages
Exam (elaborations)

Cps 188 Declarative, Cps 188 Recursions And Cps 188 Array Pointers Exam With Complete Solutions!!

Document preview thumbnail
Preview 2 out of 9 pages

CPS 188 DECLARATIVE, CPS 188 RECURSIONS AND CPS 188 ARRAY POINTERS EXAM WITH COMPLETE SOLUTIONS!!

Content preview

CPS 188 DECLARATIVE, CPS 188 RECURSIONS AND CPS 188 ARRAY
POINTERS EXAM WITH COMPLETE SOLUTIONS!!



CPS 188 DECLARATIVE

Explain pointers using the bookshelf analogy

Use the analogy of a bookshelf when referring to computer memory. Each book on the
shelf (data or variable) has its own unique location, as seen by the labels on the shelves.
This unique location is known as the memory address, and it helps find the data you are
looking for. In the case you wanted to remember where a specific book was but you
couldn't remember the name, you could remember the label on the bookshelf instead-
the location. In programming, the label is like a pointer, you can find and interact with
the data at that unique memory address, like using the shelf label to find out who the
author is, what genre it belongs to, etc.




How would I use the swap function to swap two pointers?

void swap(int a, int b) {

int temp = *a;

a = b;

*b = temp;

}




What is wrong with this code? What would I add to fix it? Why?

void swap(int a, int b) {

a = b;

b = a;

}

void swapCorrect(int a, int b) {

, int temp = *a;

a = b;

*b = temp;

}

If you try to simply use a = b, b = a, then you would lose the original value of a before you
could even swap the values. Using a temporary variable allows you to hold the original
value of a while you swap




What is wrong with this code?

void ascendingOrder(int a, int b, int *c) {

if (a > b) {

swap(a, b);

}

if (b > c) {

swap(b, c);

}

if (a > c) {

swap(a, c);

}

}

Error in the swap function. In the third if statement, the correct code should be

if (a > b) {

swap(a, b);

}




What is wrong with this code?

Document information

Uploaded on
April 14, 2025
Number of pages
9
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$13.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Braxton
3.6
(16)
Sold
76
Followers
45
Items
2101
Last sold
2 weeks ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions