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, 04.07.2019 18:10
Apipe with an outside diameter of 15 cm is exposed to an ambient air and surrounding temperature of -20°c. the pipe has an outer surface temperature of 65°c and an emissivity of 0.85. if the rate of heat loss from the pipe surface is 0.95 kw per meter of length, the external convective heat transfer coefficient (h) is: (a) 12.5 w/m"k (b) 18.6 w/mk (c) 23.7 w/mk (d) 27.9 w/mk (e) 33.5 w/mk
Answers: 1
question
Engineering, 04.07.2019 18:10
Assuming compressible flow of air and that the measurements are done at flagstaff a pitot static tube that gives the difference of total and static pressure measures 0.35 m of mercury. what is the velocity of air? assume the temperature to be 300k. (submit your excel or matlab calculation sheet)
Answers: 1
question
Engineering, 04.07.2019 18:10
Which of the following refers to refers to how well the control system responds to sudden changes in the system. a)-transient regulation b)- distributed regulation c)-constant regulation d)-steady-state regulation
Answers: 1
question
Engineering, 04.07.2019 18:20
How much power could a wind turbine produce if it had the following specifications? cp = 0.45 -d=1.2kg/m3 d=50m v 5m/s
Answers: 2
You know the right answer?
Common Mistakes in C

5 Points

Each of the following code samples below is ma...
Questions
question
Biology, 22.07.2021 23:20
question
Biology, 22.07.2021 23:20