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)

CS 2505 Exam 2 UPDATED QUESTIONS AND CORRECT ANSWERS

Rating
-
Sold
-
Pages
15
Grade
A+
Uploaded on
01-05-2026
Written in
2025/2026

CS 2505 Exam 2 UPDATED QUESTIONS AND CORRECT ANSWERS How do you create an array dynamically? - CORRECT ANSWER sizeof(int) ); Free(numbers); - Dynamically allocated data is stored on the heap How do you create an array statically? - CORRECT ANSWER - Statically allocated data is created on the run-time stack How do you free a dynamically allocated array? - CORRECT ANSWER int *numbers = malloc(size * char buffer[100] = {0}; free(numbers); What does free do, or not do, to a pointer after it is called? - CORRECT ANSWER returns the memory that was assigned to a pointer back to the system. - free may only be used on pointers that have been allocated using malloc and friends. - free may only be used 1 time on a pointer. - free does not automatically reset the pointer to NULL - free - After using free the pointer is still a variable and can be reused, assuming you allocate it new memory - You should always NULL out a pointer after you free it. What is the [ ] notation really doing? - CORRECT ANSWER Array names are essentially constant pointers- meaning only the address of the first element is stored- and the location of the array elements may not be moved...it's constant Array[0] = 10; //is the same as *(array+0) = 10; What is a memory leak? - CORRECT ANSWER allocated but never deallocated. - When memory is allocated, be sure to deallocate it. - A memory leak occurs when memory is

Show more Read less
Institution
CS
Course
CS

Content preview

CS 2505 Exam 2 UPDATED QUESTIONS
AND CORRECT ANSWERS
How do you create an array dynamically? - CORRECT ANSWER int *numbers = malloc(size *
sizeof(int) );

Free(numbers);

- Dynamically allocated data is stored on the heap



How do you create an array statically? - CORRECT ANSWER char buffer[100] = {0};

- Statically allocated data is created on the run-time stack



How do you free a dynamically allocated array? - CORRECT ANSWER free(numbers);



What does free do, or not do, to a pointer after it is called? - CORRECT ANSWER - free
returns the memory that was assigned to a pointer back to the system.

- free may only be used on pointers that have been allocated using malloc and friends.

- free may only be used 1 time on a pointer.

- free does not automatically reset the pointer to NULL

- After using free the pointer is still a variable and can be reused, assuming you allocate it new
memory

- You should always NULL out a pointer after you free it.



What is the [ ] notation really doing? - CORRECT ANSWER Array names are essentially
constant pointers- meaning only the address of the first element is stored- and the location of the array
elements may not be moved...it's constant

Array[0] = 10; //is the same as

*(array+0) = 10;



What is a memory leak? - CORRECT ANSWER - A memory leak occurs when memory is
allocated but never deallocated.

- When memory is allocated, be sure to deallocate it.

, - For example, if a function creates an array and returns it to another function, that second function is
responsible for cleaning the memory.



What tool do we use to help detect memory leaks? - CORRECT ANSWER Valgrind is a tool
that can help find memory issues.



How do you use realloc and what is it used for? - CORRECT ANSWER - realloc will attempt to
resize the current memory to the requested size.

- If it can do so in the same memory location now memory is moved

- If it cannot, then realloc will:

1. Allocate new memory of the requested size somewhere else,

2. Copy the existing memory into the new memory,

3. Release the old memory, and

4. Return a pointer to the new memory



How can consts be used with pointers?

- const targets

- const pointers

- all const - CORRECT ANSWER Can be used in 4 different ways:

1. No const

Int *ptr; //ptr is a pointer to an int. Both can be changed

2. Constant pointer

Int * const ptr; //ptr is a constant pointer to an int.//ptr cannot be changed. Target can be.

3. Constant target

Const int *ptr; //ptr is a pointer to an int constant//ptr can be pointed to a new target, but target cannot
be changed

4. Constant pointer and target

Const int * const ptr;//ptr is a constant pointer to a constant int.//all is contant and cannot be chagned.



What is pointer casting? - CORRECT ANSWER Casting a pointer to a pointer of a different
size can yield in different amounts of data being dereferenced.

- For example,

Written for

Institution
CS
Course
CS

Document information

Uploaded on
May 1, 2026
Number of pages
15
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$11.99
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

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.
STANFORDTOPGRADES Stanford University
Follow You need to be logged in order to follow users or courses
Sold
56
Member since
1 year
Number of followers
2
Documents
7115
Last sold
3 days ago
TOPSELLER

Hi there! I'm dedicated to sharing my high-quality study guides and helpful EXAM Materials to make your learning easier and more efficient. All my materials are well-organized and tailored to help you ace your courses. I offer genuine and dependable exam papers that are directly obtained from well-known, reputable institutions as a highly regarded professional who specializes in sourcing study materials. Kindly don't hesitate to contact me, my study guides, notes and exams or test banks, are 100% graded and fully guaranteed

Read more Read less
3.8

8 reviews

5
3
4
1
3
3
2
1
1
0

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