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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started