For this problem, assume the following declaration: int i a) Declare a pointer t
ID: 3820556 • Letter: F
Question
For this problem, assume the following declaration: int i a) Declare a pointer to an int, named iptr b) Point iptr at i c) Write a line of code that assigns to i the value 17, without actually using i on the left-hand side of an assignment statement For this problem, you must use malloc. Recall that malloc takes as its only parameter the number of bytes to allocate and returns a void pointer, i e., the return type is void a) Write line of code that dynamically allocates 100 int values on the heap using a call to malloc. Point at this memory with an appropriately-declared pointer, named arr. b) Fill in the if statement that checks to see if the previous malloc succeeded if printf ("malloc succeeded. c) Write a line of code that frees up the memory at which arr points For this problem, assume the following: int myArray [99] Without using ls... a) what is the address of the fifth element of my Array? b) What is the value of the seventh element of my Array? Write a void function that can be used to swap the value of two ints. Give the function header and body void swap //swapExplanation / Answer
HI, I have answered all partes of First 2 Questions.
Please repost other in separate post.
PLease let me know in case of any issue in ansered part.
Part1)
int i;
a)
int *iptr;
b)
iptr = &i;
c)
*iptr = 17;
Part2)
a)
int *arr = (int *)malloc(100*sizeof(int));
b)
if( arr != NULL){
printf("malloc succeeded");
}
c)
free(arr);
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.