Common Mistakes in C
5 Points
Each of the following code samples below is ma...
![Engineering](/tpl/images/cats/User.png)
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
![answer](/tpl/images/cats/otvet.png)
Answers: 1
Other questions on the subject: Engineering
![image](/tpl/images/cats/User.png)
![image](/tpl/images/cats/User.png)
Engineering, 03.07.2019 23:20, abbz13
Two technicians are discussing the intake air temperature (iat) sensor. technician a says that the computer uses the iat sensor as a backup to the engine coolant temperature (ect) sensor. technician b says that the powertrain control module (pcm) will subtract the calculated amount of fuel if the air measures hot. who is correct
Answers: 3
![image](/tpl/images/cats/User.png)
Engineering, 04.07.2019 18:10, tjeffers90028
Refrigerant 134a enters an insulated compressor operating at steady state as saturated vapor at -26°c with a volumetric flow rate of 0.18 m3/s. refrigerant exits at 9 bar, 70°c. changes in kinetic and potential energy from inlet to exit can be ignored. determine the volumetric flow rate at the exit, in m3/s, and the compressor power, in kw.
Answers: 1
![image](/tpl/images/cats/User.png)
Engineering, 04.07.2019 18:10, skpdancer1605
Ariver flows from north to south at 8 km/h. a boat is to cross this river from west to east at a speed of 20 km/h (speed of the boat with respect to the earth/ground). at what angle (in degrees) must the boat be pointed upstream such that it will proceed directly across the river (hint: find the speed of the boat with respect to water/river)? a 288 b. 21.8 c. 326 d. 30.2
Answers: 3
Do you know the correct answer?
Questions in other subjects:
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/fizika.png)
Physics, 03.03.2021 20:10
![Konu](/tpl/images/cats/mat.png)
Mathematics, 03.03.2021 20:10
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/obshestvoznanie.png)
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/istoriya.png)
History, 03.03.2021 20:10
![Konu](/tpl/images/cats/himiya.png)
Chemistry, 03.03.2021 20:10
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/en.png)
English, 03.03.2021 20:10