Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

ECE220 – Programming for Electrical Engineering: ECE 220 Midterm (A)| questions and answers latest spring 2026 - University of Alberta.

Beoordeling
-
Verkocht
-
Pagina's
11
Cijfer
A+
Geüpload op
13-04-2026
Geschreven in
2025/2026

ECE220 – Programming for Electrical Engineering page 1 of 11 ECE 220 Midterm (A) March 11th, 2026, 1:00PM Signature: Instructions • PRINT YOUR NAME and Student ID into the boxes above. • Sign in the Signature box. • Write your name and your Student ID on the General Purpose Answer Sheet. Your Student ID should be left-aligned, e.g. • Fill in the bubbles on the General Purpose Answer Sheet to code in your name and ID. • Write 100000 in Special Code on the General Purpose Answer Sheet. • This is a CLOSED BOOK exam. Time allowed: 50 minutes. • Calculators, cell phones, or computers of any kind are not permitted. • This exam, worth 90 points, counts 15% toward your final grade in this course. • Write your answers properly on the answer sheet with an HB pencil. If the optical reader cannot clearly read your answer, the mark on that question will be 0. • All the C code provided in this exam is ANSI standard and uses the ASCII character set. • For questions regarding code fragments, assume that all the necessary header files and surrounding code are provided. • Questions are weighted differently in each part: Points o Part 1 - (5 questions at 3 point each) 15 o Part 2 - (5 questions at 5 points each) 25 o Part 3 - (5 questions at 6 points each) 30 o Part 4 - (2 questions at 10 points each) 20 • This question booklet must be returned with your General Purpose Answer Sheet for you to get credit for this exam. • IMPORTANT: Answer Parts 1, 2 and 3 in the General Purpose Answer Sheet. For Part 4 use the space provided in this booklet. Name: Student ID:ECE220 – Programming for Electrical Engineering page 2 of 11 Part 1: [15 points total – 5 Questions – 3 points each] – Multiple Choice Questions Answer the following questions starting at question number 1 on the front of your General Purpose Answer Sheet] 1. What is the output produced by the following code? int x = 4, y = 7; int *p; p = &x; *p = y + 1; printf("%d %dn", x, y); a) 4 7 b) 5 7 c) 7 8 d) 8 8 e) 8 7 2. What is the value of *(arr+2) of the following array? int arr[4] = {5, 10, 15, 20}; a) 5 b) 10 c) 15 d) 20 e) address of arr[2] 3. Which of the following correctly declares (is a prototype) a function that takes a pointer to integer and returns an integer? a) int fun(int); b) int * fun(int *); c) void fun(int *); d) int fun(int *); e) char = fun(int);ECE220 – Programming for Electrical Engineering page 3 of 11 4. What is the output of the following code? int a[3] = {2, 4, 6}; int *p = a; printf("%d ", *p); p++; printf("%dn", *p); a) 2 4 b) 2 6 c) 4 6 d) 4 4 e) undefined behavior 5. What is wrong with the following code? char word[10] = "hello"; word = "abc"; a) nothing is wrong b) array index out of bounds c) string too long d) you cannot assign to an array name e) "abc" is not a stringECE220 – Programming for Electrical Engineering page 4 of 11 Part 2. [25 points total – 5 Questions – 5 points each] – Multiple Choice Questions [Answer the following questions starting at question number 6 on the front of your General Purpose Answer Sheet.] 6. What is the output of this nested switch statement? int x = 2, y = 3; switch (x) { case 1: printf("A"); break; case 2: printf("B"); switch (y) { case 1: printf("C"); break; case 2: printf("D"); break; default: printf("E"); } default: printf("F"); } a) BEF b) BC c) BE d) BD 7. What is the problem with this function? int *fun(void) { int x = 5; return &x; } a) it returns too many values b) x should be float c) it returns the address of a local variable d) functions cannot return pointers e) no problemECE220 – Programming for Electrical Engineering page 5 of 11 8. What is printed? int x = 7; int *p = &x; (*p)++; printf("%dn", x); a) 7 b) 8 c) address of x d) undefined behavior e) compilation error 9. What is printed? int *p; p = malloc(sizeof(int)); *p = 5; free(p); printf("%dn", *p); a) 0 b) 5 c) address of p d) undefined behavior e) compilation errorECE220 – Programming for Electrical Engineering page 6 of 11 10. What is printed? void fun(int *p) { *(p + 1) = 20; } int main() { int a[3] = {5,10,15}; fun(&a[-1]); printf("%d %dn", a[0], a[1]); return 0; } a) 5 10 b) 20 10 c) 5 20 d) 20 5 e) index out of rangeECE220 – Programming for Electrical Engineering page 7 of 11 Part 3: [30 points total – 5 Questions – 6 points each] – Multiple Choice Questions [Answer the following questions starting at question number 11 on the front of your General Purpose Answer Sheet.] 11. What is the value of count after this code runs? int arr[6] = {2, 5, 8, 1, 6, 4}; int *p = arr; int count = 0; for (int i = 0; i 6; i++) { if (*(p + i) 4) count++; } a) 6 b) 5 c) 4 d) 3 e) 2 12. What is the final value of count? int count = 0; int i = 1; while (i = 10) { if (i % 3 == 0 || i % 4 == 0) { count++; } else { count += 2; } i++; } a) 5 b) 7 c) 10 d) 12 e) 15ECE220 – Programming for Electrical Engineering page 8 of 11 13. What is wrong with the following code? #include stdio.h #include stdlib.h int main() { char str[] = "Hello"; char *copy; int i = 0; copy = (char *)malloc(6 * sizeof(char)); while (str[i] != '0') { copy[i] = str[i]; i++; } copy[i] = '0'; free(copy); printf("%sn", copy); return 0; } a) malloc() cannot be used for strings b) the null terminator is missing c) memory is freed and then used d) free(copy) should be before copy[i] = '0' e) nothing is wrong 14 e). F What will this code print? int arr[5] = {1, 2, 3, 4, 5}; int *p = &arr[4]; int sum = 0; for (int i = 4; i; i--) { sum += *(p - i); if (i % 2 == 0) continue; sum += 3; } printf("%d", sum); a) 10 b) 13 c) 14 d) 16 e) 17ECE220 – Programming for Electrical Engineering page 9 of 11 15. Analyze the function below. void mystery(char *str) { char *start = str; char *end = str; char temp; while(*end && *end != '#') end++; end--; while(start end) { temp = *start; *start = *end; *end = temp; start++; end--; } } What will the following code print? char array[] = "March#11.2026"; mystery(array); printf("%s" , array); a) March#11.2026 b) 2026.11#March c) hcraM#11.2026 d) #11.2026March e) #11.2026hcraMECE220 – Programming for Electrical Engineering page 10 of 11 Part 4: [20 points total – 2 Questions – 10 points each] – Programming Questions [Use the space in the booklet to provide your answers.] 16.Write a function that takes a string as input and returns the number of lowercase letters in the string. For example: if the input string is "AbcDxy1", the function returns 4. Prototype: int count_lowercase(char *str); Notes: count only characters from 'a' to 'z' /* space for your function code */ int count_lowercase(char *str) { int i = 0; int count = 0; while(str[i++]!=0) { if (str[i] = 'a' && str[i] = 'z') { count ++; } } return count; }ECE220 – Programming for Electrical Engineering page 11 of 11 17. Write a function char* str_copy_until(char* str, char symbol) that takes a string and a character symbol, and returns a new dynamically allocated string only with the part before the first occurrence of symbol (inclusive), while the rest of the string is not copied. For example, when the string "This is nice" and a character 's'are put into the function, the function returns the following string "This". Do not modify the original string. Handle memory allocation properly, it means allocate only as much as is needed. char* str_copy_until(char* str, char symbol) { char *a = NULL; //pointer (use it in memory allocation) // your code here int i = 0; int size = 0; while(str[i]!= xyz) i++; size = i+1; a = (char *)malloc(size); if (a == NULL){ printf("no memoryn"); exit (1); } for (i=0; isize; i++) a[i] = str[i]; a[i] = 0; return a; } END OF EXAM

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

ECE220 – Programming for Electrical Engineering


ECE 220
Midterm (A)
March 11th, 2026, 1:00PM


Name:
Student ID:
Signature:


Instructions
• PRINT YOUR NAME and Student ID into the boxes above.
• Sign in the Signature box.
• Write your name and your Student ID on the General Purpose Answer Sheet. Your
Student ID should be left-aligned, e.g.




• Fill in the bubbles on the General Purpose Answer Sheet to code in your name and ID.
• Write 100000 in Special Code on the General Purpose Answer Sheet.

• This is a CLOSED BOOK exam. Time allowed: 50 minutes.
• Calculators, cell phones, or computers of any kind are not permitted.
• This exam, worth 90 points, counts 15% toward your final grade in this course.
• Write your answers properly on the answer sheet with an HB pencil. If the optical reader
cannot clearly read your answer, the mark on that question will be 0.
• All the C code provided in this exam is ANSI standard and uses the ASCII character set.
• For questions regarding code fragments, assume that all the necessary header files
and surrounding code are provided.
• Questions are weighted differently in each part: Points
o Part 1 - (5 questions at 3 point each) 15
o Part 2 - (5 questions at 5 points each) 25
o Part 3 - (5 questions at 6 points each) 30
o Part 4 - (2 questions at 10 points each) 20
• This question booklet must be returned with your General Purpose Answer Sheet for
you to get credit for this exam.
• IMPORTANT: Answer Parts 1, 2 and 3 in the General Purpose Answer Sheet. For
Part 4 use the space provided in this booklet.




page 1 of 11

, ECE220 – Programming for Electrical Engineering


Part 1: [15 points total – 5 Questions – 3 points each] – Multiple Choice Questions
Answer the following questions starting at question number 1 on the front of your General
Purpose Answer Sheet]


1. What is the output produced by the following code?
int x = 4, y = 7;
int *p;
p = &x;
*p = y + 1;
printf("%d %d\n", x, y);

a) 4 7
b) 5 7
c) 7 8
d) 8 8
e) 8 7




2. What is the value of *(arr+2) of the following array?
int arr[4] = {5, 10, 15, 20};

a) 5
b) 10
c) 15
d) 20
e) address of arr[2]




3. Which of the following correctly declares (is a prototype) a function that takes a pointer to
integer and returns an integer?

a) int fun(int);
b) int * fun(int *);
c) void fun(int *);
d) int fun(int *);
e) char = fun(int);



page 2 of 11

Geschreven voor

Instelling
Studie
Vak

Documentinformatie

Geüpload op
13 april 2026
Aantal pagina's
11
Geschreven in
2025/2026
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$14.23
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
elam17799 Brighton College
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
19
Lid sinds
1 jaar
Aantal volgers
1
Documenten
201
Laatst verkocht
3 weken geleden
Explore thousands of course and professor reviews

Explore thousands of course and professor reviews from Canada Universities and Colleges students. Feel free to inbox me for any paper you wish to have.

4.0

2 beoordelingen

5
0
4
2
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen