subject
Engineering, 14.02.2020 20:15 desi9750

Common Mistakes in C

5 Points

Each of the following code samples below is making a common mistake in C. From the options:

probable segfault, double free, incorrect use of free, logic error, memory leak, and no error

select the error type that best categorizes the mistake.

You can assume all the code has the necessary #include macros. Also you should assume that the system is 32-bit.

1) #DEFINE PASSWORD "correct horse battery staple"
char *check_permissions (char *user_guess) {
if (user_guess = PASSWORD) {
return "access granted";
}
return "access denied";
}
#DEFINE PASSWORD correct horse battery staple char *check_permissions (char *user_guess) f if (user_guessPASSWORD) return

2) #DEFINE PASSWORD "correct horse battery staple"
char *check_permissions (char *user_guess) {
if (user_guess == PASSWORD) {
return "access granted";
}
return "access denied";
}
#DEFINE PASSWORD correct horse battery staple char *check_permissions (char *user_guess) if (user_guess PASSWORD) return a

3) int main () { char *x = malloc(0x * sizeof(char)); x[0] = '!'; }

int main )( char *x malloc (0xsizeof (char));

4) int foo () { int *x = malloc(20); x[0] = x[1] = 1; x[2] = x[0] + x[1]; x[3] = 99; return x[3]; }

int foo ) int *x = malloc (20); 2 + X x[3]99; return x[3];

5) int main () {

char *x = "patrick";
printf("%s", x);
free(x); // tidy up
}
int main ) char *x patrick; printf ( %s , x ) ; free(x): 17 tidy up

ansver
Answers: 1

Another question on Engineering

question
Engineering, 03.07.2019 19:30
When using the ohmmeter function of a digital multimeter, the leads are placed in what position relative to the component being tested? a. parallel b. control c. series d. line
Answers: 3
question
Engineering, 04.07.2019 18:10
Aflywheel accelerates for 5 seconds at 2 rad/s2 from a speed of 20 rpm. determine the total number of revolutions of the flywheel during the period of its acceleration. a.5.65 b.8.43 c. 723 d.6.86
Answers: 2
question
Engineering, 04.07.2019 18:10
Which of the following controllers anticipates the future from the slope of errors over time? a)-proportional b)-on/off c)-integral d)-derivative.
Answers: 2
question
Engineering, 04.07.2019 18:20
Find the minimum film thickness for a journal bearing with the data below. shaft diameter, d-50 mm, clearance ratio, cdratio? 0.001, shaft speed, n 2000 rpm; bearing length. i 200 mm; eccentricity ration, ? -0.55. ( note, cdratio-ca/d) the minimum film thickness is um
Answers: 2
You know the right answer?
Common Mistakes in C

5 Points

Each of the following code samples below is ma...
Questions
question
Mathematics, 12.11.2020 20:40
question
Mathematics, 12.11.2020 20:40
question
Mathematics, 12.11.2020 20:40
question
Geography, 12.11.2020 20:40
question
Mathematics, 12.11.2020 20:40
question
Biology, 12.11.2020 20:40
question
Social Studies, 12.11.2020 20:50
Questions on the website: 13722363