Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

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

Rating
-
Sold
-
Pages
9
Grade
A+
Uploaded on
14-04-2025
Written in
2024/2025

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

Institution
CPS 188 DECLARATIVE, CPS 188 RECURSIONS
Module
CPS 188 DECLARATIVE, CPS 188 RECURSIONS

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?

Written for

Institution
CPS 188 DECLARATIVE, CPS 188 RECURSIONS
Module
CPS 188 DECLARATIVE, CPS 188 RECURSIONS

Document information

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

Subjects

$13.49
Get access to the full document:

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


Also available in package deal

Thumbnail
Package deal
CPS 188 PACKAGED EXAMS!!
-
5 2025
$ 68.45 More info

Get to know the seller

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 West Virgina University
View profile
Follow You need to be logged in order to follow users or courses
Sold
67
Member since
2 year
Number of followers
45
Documents
2078
Last sold
2 weeks ago

3.3

12 reviews

5
2
4
5
3
2
2
0
1
3

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight 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 smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions