I\'m C please! Identify, fix. and explain what errors, if any. exist within the
ID: 3926417 • Letter: I
Question
I'm C please! Identify, fix. and explain what errors, if any. exist within the two main programs. int main(void) {int* p = maIIoc(42); char* q = (char*) p; strcpy(q. "random string"); *p = 65;} int main(void) {int* p = (int*) malloc(sizeof(int)); int* q = p; *p = 42; frce(p); frec(q); *p = 9; struct node {int value; struct node* next; Write the following function: struct node * find_last (struct node* list, int n); The list parameter points to a linked list. The function should return a pointer to the last node that contains n; it should return NULL if n does not appear in the list.Explanation / Answer
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.