211-lab-review

.pdf

School

University of Illinois, Chicago *

*We aren’t endorsed by this school

Course

211

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

4

Uploaded by UltraFang12731

Question : When does it return true? Consider the following function bool mystery(const char s1[ ], const char s2[ ]) { int i=0; bool result; while ( s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0' ) ++i; if ( s1[i] == '\0' && s2[i] == '\0' ) result = true; else result = false; return result; } Options: When s1 is a different length than s2 When we successfully copy s2 into s1 When s1 and s2 are the same length When s1 and s2 have the same length and same characters Answer : When s1 and s2 have the same length and same characters Question : What does it do? Consider the following function: void mystery2 (char s1[], char s2[]) {
int i; for(i=0; s2[i]!='\0'; ++i) s1[i] = s2[i]; s1[i] = '\0'; } Options: Compare s1 and s2 WRONG Copy s2 into s2 COULD BE THIS Copy s1 into s2 WRONG Overwrite s1 and s2 with NULL characters OR THIS Question : C-strings automatically grow or shrink, depending on the need?* Answer : False Question : Assume we are writing a program to grow a dynamic array. Consider the following options: (How many of the above options would work correctly?) Options: Declare a larger array statically within a function. Allocate space using malloc Allocate space using calloc Allocate space using realloc Answer : 3 of them would work Question : Imagine that we have a variable declared as: int * pBestArray = NULL; And we have passed it to function void setIt(...) which changes it to point to some array, where that change is reflected back to the calling part of the program. How would we declare the parameter in the function declaration? Options: void setIt( int pBestArray); void setIt( int *pBestArray);
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help