Write and compile a C++ program that does the following task: a function, f2a(..
ID: 3657944 • Letter: W
Question
Write and compile a C++ program that does the following task: a function, f2a(...), that creates a new three-element integer array. Using pointer arithmetic, and not the traditional array[index] notation, load the values 14, 27 and 33 into the first, second and third elements, respectively of this new array. This function then returns a pointer to the new array. Write, now, a second function, f2b(...), that takes, as a parameter, an int pointer to an array. Pass the array created in f2a(...) to f2b(...) to be printed, again using pointer arithmetic, and, afterwards, destroyed. To test these functions, call them from the main function.Explanation / Answer
#include int *f2a(int *p){ scanf("%d",p); scanf("%d",p+1); scanf("%d",p+2); return p; } void f2b(int *p){ printf("%d",*p); printf("%d",*(p+1)); printf("%d",*(p+2)); } int main(){ int p[3]; f2a(p); printf(" "); f2b(p); return 0; }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.