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

Other questions on the subject: Engineering

image
Engineering, 04.07.2019 18:10, heidiburgos1own6c0
Fluids at rest possess no flow energy. a)- true b)- false
Answers: 3
image
Engineering, 04.07.2019 18:10, aaliyah80
The drive force for diffusion is 7 fick's first law can be used to solve the non-steady state diffusion. a)-true b)-false
Answers: 1
image
Engineering, 04.07.2019 18:10, leomessifanboy678
The filament of an incandescent lamp has a temperature of 2000k. calculate the fraction of radiation emitted in the visible light band if the filament is approximated as blackbody
Answers: 2
image
Engineering, 04.07.2019 18:10, oliviasoreo92
Compute the pressure drop of 30°c air flowing with a mean velocity of 8 m/s in a circular sheet-metal duct 300 mm in diameter and 15 m long. use a friction factor, f 0.02, and pair = 1.1644 kg/m a. 37.26 pa b. 25.27 pa n c. 29.34 pa d. 30.52 pa
Answers: 1
You know the right answer?
Common Mistakes in C

5 Points

Each of the following code samples below is ma...

Questions in other subjects:

Konu
Computers and Technology, 12.03.2020 17:22