Question: 1. In the main function , create a char array of 15 elements and populate it with random chars from a - z. 2. Create

1. In the main function, create a char array of 15 elements and populate it with random chars from a - z. 2. Create a regular c-type function that outputs the contents of the array AND the associated memory addresses (cast to an integer) explicitly using a for loop and the index notation: a[i] and &a[i]. Call this function from the main using the array populated in part 1. 3. Create another regular c-type function that achieves the same output using references only. In other words, use pointers, pointer arithmetic, and the dereferencing operator ( * ).

//C++ THIS is my current code to follow the promt

#include #include

using namespace std;

//Constants const int CAPACITY = 26;

//Function Declarations void randomArray(char[], int&); void outputLetters(char a[],int); void outputReference(char*,int);

int main() { srand(time(NULL)); char letters[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' }; int numOfElements = 15; outputLetters(letters,numOfElements); outputReference(letters,numOfElements);

return 0; }

//Function Definitions void randomArray(char letters[], int& numOfElements){ for (int i = 0; i < numOfElements; i++) { numOfElements[i] = letters[rand() % 26]; }

}

void outputLetters(char a[], int numOfElements) { for (int i = 0; i < numOfElements; i++) { cout << a[i] << " " << (int*)& a[i] << endl; } }

void outputReference(char* letters,int numOfElements) { for (int i = 0; i < numOfElements; i++) { cout << *(letters + i) << " " << (int*)(letters + i) << endl; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!