Im C please Identify fix and explain what errors if any exis
Solution
Please follow the code and comments for description :
3)
a)
CODE :
After the inclusion of the necessary header files to the code the execution and the compilation of the program is perfect.
#include <stdio.h> // required header files
#include <string.h>
#include <stdlib.h>
int main(void) // main driver method
{
int *p = malloc(42); // allocating the value to the pointer
char * q = (char*)p; // pointer declaration and initialisation
strcpy(q, \"random string\"); // copying the string
*p = 65; // pointer setting to a value of index
}
b)
CODE :
After the inclusion of the necessary header files to the code the execution and the compilation of the program is perfect
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
int *p = (int*)malloc(sizeof(int));
int *q = p;
*p = 42;
free(p);
free(q);
*p = 9;
}
Hope this is helpful.
