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)

EECS 2031 Software Tools midterm Exam - All answers are Correct - York University EECS 2031

Beoordeling
-
Verkocht
-
Pagina's
15
Cijfer
A+
Geüpload op
07-03-2023
Geschreven in
2022/2023

Question 1 (14.5 pts) 1.1 (0.25 pt) For the following code fragment, what is the output of the printf() statement? int x = 9, y = 13, z = 3; printf("z: %dn", z *= y + x + 2 ); z: 1.2 (1 pt) What is the output of the printf() statement? int x = 2, y = x 2; printf("%d %d %d %dn", x, y, x|y, x&y); 1.3 (1 pt) What is the output of the printf() statement? int x = 13, y = z = 10; y = x++; z += y++; printf("x:%d y:%d z:%dn", x,y,z); 1.4 (1 pt) What is the output of the printf() statement? int x = 3; int y = 4; printf("%d %d %d %dn", x | y, x & y, x || y, x && y); 1.5 (0.5 pt) What is the output of the printf() statement? int a = 6; int c = 4; float d = 1.1; short s =1; printf("x:%.3f y:%.3fn", s*a/c*d, d/c*a*s); 1.6 (0.5 pt) In 1.5, when d/c*a*s is evaluated, how many type conversions are performed? What is the type of the expression? 1.7 (0.5 pt) Recall that in ANSI-C, implicit type conversions are preformed on the following occasions 1) When the operands in an arithmetic or logical expression don’t have the same type. 2) When the type of the expression on the right side of an assignment doesn’t match the type of the variable on the left side. 72 2 8 10 0 14 14 23 7 0 1 1 1.100 1.650 three float 3) When the type of an argument in a function call doesn’t match the type of the corresponding parameter. 4) When the type of the expression in a return statement doesn’t match the function’s return type. On which of the above occasion(s), is “type promotion” performed, in which the type of the operand with the narrower type is converted to the type of the other operand? a. On 1) b. On 2) c. On 3) and 4) d. All of the above. 1.8 (1.5 pt) Consider the following ANSI-C program, where the programmer made typos on line 6 and 8, and also missed a else on line 8 #include stdio.h int main (){ int in; printf("Enter an integer: "); scanf ("%d", &in); if (in = 1) /* this is line 6 */ printf("Entered onen"); if (in = 2) /* this is line 8 */ printf("Entered twon"); else printf("Entered othersn"); return 0; } What happens when you try to compile and run the program with input 2? (chose a. or b.) a. The program does not compile, because b. The program compiles, output is What happens when you try to compile and run the program with input 36? (chose a. or b.) a. The program does not compile b. The program compiles, output is What happens when you try to compile and run the program with input 1? (chose a. or b.) a. The program does not compile b. The program compiles, output is Entered one Entered two Entered one Entered two Entered one Entered two Jun 13, 2017 (Tuesday) Name: Student ID: Page 5 of 15 1.9 (0.25pt) Recall that a gcc compilation process contains three stages. The correct order is a. Linking → Pre-processing → Compiling b. Pre-processing → Compiling → Linking c. Compiling → Pre-processing → Linking d. None of the above 1.10 (1.5 pt) Consider the following statements. For each of the statements, if the right hand side of = is a valid integer literal in ANSI-C, then specify the decimal value of x. If the right hand side of = is not a valid integer literal, specify “invalid”. int x = b; int x = 014; int x = 0X3f; int x = 032L; int x = 0xfFG; int x = 0392; 1.11 (3.75 pt) Suppose flags is an integer variable with some value. What happens to flags in each of the following 3 statements, in terms of turning on/off or keeping the bits of flags? Denote the right-most bit as bit 0, the 2nd right-most bit as bit 1… 1) flags = flags | (1 6); turn on bit 6 (right most is bit 0), keep other bits 2) flags = flags | ~(1 4); keep bit 4, turn on all other bits 3) flags = flags & 0177; keep right-most 7 bits, turn off all other bits In statement 1) and 2) above, can any of the parentheses be removed without affecting the meaning and value of the expression? If yes, specify which one(s) and briefly explain why. Now suppose you need an int mask whose binary representation is 000..... How do you declare it in ANSI-C code? List 3 ways of doing it. int mask = 41 int mask = 051 int mask = 0x29 What happens to flags in the following two statements, in terms of turning on/off or keeping bits of flags? Denote the right-most bit as bit 0, the 2nd right-most as bit 1 ... • flags = flags | mask turn on bits 0, 3, 5, keep others • flags = flags & mask keep bit 0, 3, 5, turn off all other bits invalid 63 invalid 26 12 invalid parenthesis in 1) can be removed. Because has higher precedence than |, so 1 6 is evaluated before | anyway Other slu: int mask = 1 5 | 1 3 | 1 int mask = 9 | 1 3 … anything evaluated to 41 decimal 1.12 (1.25 pt) For each of the following array declaration and initializations, determine if the statement is legal in ANSI C. If it is illegal, write ‘illegal’. If it is legal, then list (the value of) all the elements in the array, separated by comma or space. • int k[3] ={1,5,3,2,25}; illegal • int k[5] = {1}; 1 0 0 0 0 • int k[6] = {1,4,5}; 1 4 5 0 0 0 • int k[] ={1,5,3,2,25}; 1 5 3 2 25 • int k2[] = k; illegal 1.13 (1.5 pt) Given the statement char messages[3][20] = {"Hello", "Hi", "There"}; • What is the value of sizeof(messages)? 3 * 20 * 1 = 60 (bytes) • write a single C statement to change "Hi" to "How are you" strcpy (messages[1], “How are you”) or sprintf(messages[1], “%s”,”How are you”) or sprintf(messages[1],”How are you”)

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

MIDTERM TEST
EESC 2031 – Software Tools
June 13, 2017

Last Name: _____________________ First Name: __________________________

Student ID: __ __ __ __ __ __ __ __ __ EECS user name:_______________________


TIME LIMIT: 110 minutes

• This is a closed-book test. No books and notes are allowed.
• Extra space for answers can be found at the end of the test booklet.

• Assume that
o size of char is 1 (byte);
o size of short integer is 2 (bytes);
o size of integer is 4 (bytes);
o size of long integer is 8 (bytes);
o size of float is 4 (bytes);
o size of double is 8 (bytes);
• Also assume that the size of a pointer is 8 (bytes).




Question Value Mark
1 14.5
2 12
3 23.5+1.5 bonus
TOTAL 50 +1.5 bonus

Good Luck

,

Geschreven voor

Vak

Documentinformatie

Geüpload op
7 maart 2023
Aantal pagina's
15
Geschreven in
2022/2023
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$10.49
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.
ExamsConnoisseur Self
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
587
Lid sinds
3 jaar
Aantal volgers
344
Documenten
1492
Laatst verkocht
2 weken geleden

4.2

68 beoordelingen

5
40
4
11
3
13
2
1
1
3

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