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 261 Data Structures questions(solved & verified for accuracy)

Rating
-
Sold
-
Pages
6
Grade
A+
Uploaded on
01-11-2024
Written in
2024/2025

CS 261 Data Structures questions(solved & verified for accuracy)

Institution
CS061
Course
CS061

Content preview

CS 261 Data Structures
questions(solved & verified for
accuracy)
What will be the output?


int arr[] = {1,2,3,4,5);
int *ptr = arr;
*ptr = 10;
printf("Output 1: %d \n", arr[0]);
printf("Output 2: %d \n", *(ptr+2)); - answer Output 1: 10
Output 2: 3


Output?


int total = 0;
For(int i = 1; i <= 6; i++){
if(i%2 == 0){
total += i;
printf("total = %d \n", total);
}
} - answer total = 2
total = 4
total = 6
total = 12

, What is a dynamic array in C? - answer An array whose size can be
changed at runtime


Value of ptr after memory allocation?


int *ptr;
ptr = (int*)malloc(sizeof(int) *5); - answer Address of first element.


sizeof(int) makes 4 bytes, times 5 equals 20 bytes. int* before
malloc specifies the pointer returned by malloc will point to an
integer.


Which header file do you include to use to include the malloc
function in C? - answer <stdlib.h>


How would you write a struct with two member int and char? -
answer struct MyStruct{ int a; char b;};


What is printed?


int a=10, b=20, c=30;
int *array[3] = {&a, &b, &c};
printf("%d", *array[2]); - answer 30


Output?


int *arr = (int*)malloc(6*sizeof(int));
for(int i =0; i < 6;i++){
arr[i] = i * 2;
}

Written for

Institution
CS061
Course
CS061

Document information

Uploaded on
November 1, 2024
Number of pages
6
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$15.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

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.
FREEMANSHARP Havard School
View profile
Follow You need to be logged in order to follow users or courses
Sold
145
Member since
2 year
Number of followers
70
Documents
7648
Last sold
1 week ago
FREEMANSHARP

In this page you will find all exams , flashcards , quizzes and package deals offered by seller Freemansharp

3.6

29 reviews

5
9
4
7
3
7
2
3
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 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

Frequently asked questions