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
Aloaded platform of total mass 500 kg is supported by a dashpot and by a set of springs of effective stiffness 72 kn/m. it is observed that when the platform is depressed through a distance x = 12.5 cm below its equilibrium position and then released without any initial velocity; it reaches its equilibrium position in the shortest possible time without overshoot. find the position and velocity of the loaded platform 0.10 sec. after its release. if a further load of 400 kg is added to the platform, find, i) the frequency of damped vibrations, and i) the amplitude of vibration after 2 complete oscillations, given that the initial amplitude is 15 cm.
Answers: 1
question
Engineering, 04.07.2019 18:10
For the closed feedwater heater below, feedwater enters state 3 at a pressure of 2000 psia and temperature of 420 Ā°f at a rate of ix10 ibhr. the feedwat extracted steam enters state 1 at a pressure of 1000 psia and enthalpy of 1500 btu/lbm. the extracted er leaves at an enthalpy of 528.7 btu/lbm steam leaves as a saturated liquid. (16) a) determine the mass flow rate of the extraction steam used to heat the feedwater (10) b) determine the terminal temperature difference of the closed feedwater heater
Answers: 3
question
Engineering, 04.07.2019 18:10
At 12 noon, the count in a bacteria culture was 400; at 4: 00 pm the count was 1200 let p(t) denote the bacteria cou population growth law. find: (a) an expression for the bacteria count at any time t (b) the bacteria count at 10 am. (c) the time required for the bacteria count to reach 1800.
Answers: 1
question
Engineering, 04.07.2019 19:10
Abarometer contains mercury with a density of 13600 kg/m3. atmospheric conditions are 95.8 kpa and 20 Ā°c at 20 Ā°c, the vapor pressure of the mercury is 0.000173 kpa. the column of mercury will rise to a height of most nearly. select one: a)- 0.38 m b)- 0.82 m c)- 0.48 m d)- 0.72 m
Answers: 1
You know the right answer?
Common Mistakes in C

5 Points

Each of the following code samples below is ma...
Questions
Questions on the website: 13722361