A)
Address of (&) operator:
The main purpose of address operator “&” operator in pointers is to return the memory address of variables.
When the address of operator “&” is placed before the pointer variable, it will hold address of the pointer variable.
Example
//include necessary header
#include <iostream>
#include <string>
using namespace std;
//main method
int main()
{
//variable declaration
int a;
//display the address of the variable a
cout << &a;
}
Representing array using pointer notation:
- In general, array will have a continuous allocation of memory bytes, to represent the values present in the array it can be represented using its subscript value.
- So, to represent the values using pointer notation with an indirection operator the name of the array plus the subscript representing the value needs to be specified.
- When we represent only the array name, it will indicate the first element of the array.
- To represent the next element we need to increment the values by one to find the proceeding elements of the array.
- When “&” operator is used before an array it will return the address of the corresponding value.
B)
Address of (&) operator:
The main purpose of address operator “&” operator in pointers is to return the memory address of variables.
When the address of operator “&” is placed before the pointer variable, it will hold address of the pointer variable.
Example Program:
//include necessary header
#include <iostream>
#include <string>
using namespace std;
//main method
int main()
{
//variable declaration
int a;
//display the address of the variable a
cout << &a;
}
Representing array using pointer notation:
- In general, array will have a continuous allocation of memory bytes, to represent the values present in the array it can be represented using its subscript value.
- So, to represent the values using pointer notation with an indirection operator the name of the array plus the subscript representing the value needs to be specified.
- When we represent only the array name, it will indicate the first element of the array.
- To represent the next element we need to increment the values by one to find the proceeding elements of the array.
- When “&” operator is used before an array it will return the address of the corresponding value.
C)
Address of (&) operator:
The main purpose of address operator “&” operator in pointers is to return the memory address of variables.
When the address of operator “&” is placed before the pointer variable, it will hold address of the pointer variable.
Example Program:
//include necessary header
#include <iostream>
#include <string>
using namespace std;
//main method
int main()
{
//variable declaration
int a;
//display the address of the variable a
cout << &a;
}
Representing array using pointer notation:
- In general, array will have a continuous allocation of memory bytes, to represent the values present in the array it can be represented using its subscript value.
- So, to represent the values using pointer notation with an indirection operator the name of the array plus the subscript representing the value needs to be specified.
- When we represent only the array name, it will indicate the first element of the array.
- To represent the next element we need to increment the values by one to find the proceeding elements of the array.
- When “&” operator is used before an array it will return the address of the corresponding value.
D)
Address of (&) operator:
The main purpose of address operator “&” operator in pointers is to return the memory address of variables.
When the address of operator “&” is placed before the pointer variable, it will hold address of the pointer variable.
Example Program:
//include necessary header
#include <iostream>
#include <string>
using namespace std;
//main method
int main()
{
//variable declaration
int a;
//display the address of the variable a
cout << &a;
}
Representing array using pointer notation:
- In general, array will have a continuous allocation of memory bytes, to represent the values present in the array it can be represented using its subscript value.
- So, to represent the values using pointer notation with an indirection operator the name of the array plus the subscript representing the value needs to be specified.
- When we represent only the array name, it will indicate the first element of the array.
- To represent the next element we need to increment the values by one to find the proceeding elements of the array.
- When “&” operator is used before an array it will return the address of the corresponding value.
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
- You are given the following two dimensional arrays of people and their birth months: String [][] people = {{June, May, March, June, May, March, February, June, May, January, May, March}, {John, Mary, Peter, Bob, Sam, Dan, Judith, Gary, Tiff, Suzy, Jim, Jane}} 1) Create an enum type for the the first six months of the year 2) Randomly select a month from this enum 3) Loop through the array of people and make a list of all the people whose birthdays correspond to the month that was randomly chosen above. I ONLY NEED THE ANSWERS TO 2 AND 3. Please provide the codearrow_forwardTo initialize a String array names to store the three Strings "Huey", "Duey" and “Louie", you would do which of the following? { "Huey", "Duey", "Louie"}; ew String{"Huey", "Duey", "Louie"}; { "Huey", "Duey", "Louie"}; { "Huey", "Duey“, "Louie"}; a. String[] names b. String[] names %3D %D new c. String names d. String names[3] e. String names; %3D %3D names[0] "Huey"; names[1] "Duey“; %3D names[2] "Louie“;arrow_forwardProgramming language is C#arrow_forward
- Largest/Smallest Array Values Write a program that lets the user enter 10 values into an array. The program should then display the largest and smallest values stored in the array. Do question 7(above) again this time using 5 functions. void getValues(int [], int); void displayValues(const int[], int); int largest(const int[],int); int smallest(const int[],int); void displayLargestSmallest(int,int);arrow_forward#include <stdio.h>int main(){int d;int s[20],i, r, p, lg=0,m;char c;printf("Enter number of salesman(max 20): ");scanf("%d", &d);for(i=0; i<d; i++){ printf("\n salesman %d sales: ");scanf("%d", &s[i]);}for(i=0; i<d; i++){for(r=i+1; j<d; r++){if(s[i] > s[r]){p= s[i];s[i] = s[r];s[j] = p;}}}printf("\nsalesman lowest to highest: ");for(i=0; i<d; i++){printf("%d\t", s[i]);}for(i=0;i<m;i++){printf("\n highest sales: %d ",lg);if(lg<=s[i])lg=s[i];break;}getch();} >>> the upper part output should be like this enter number of salesman (max 20): 5 salesman 1 500 salesman 2 300 salesman 3 1000 salesman 4 200 salesman 5 1000 in the lower part the lowest to highest the output should become like this salesman 4 200 salesman 2 300 salesman 1 500 salesman 3 1000 salesman 5 1000 highest total sales : 2000arrow_forwardJAVA Programming Problem 5 – CharacterArray Write a program which will store the following string into a character array: 6901 Sudley Road Manassas VA Your program will display each original character, determine and display whether the character is a digit or a letter, and redisplay the character according to the directions below. Directions Create a class called CharacterArray. The scanner class is not required. Initialize the character array with the given string. Write a program which will accept an alpha numeric string at the keyboard. Store the string, of any length, into a character array, for example: RBDB Manassas Campus 6901 Sudley Road Manassas VA 20109 For each visible character: Display the original character Determine and display whether the character is a digit or a letter If the character is a lower case letter, redisplay the character in upper case If the character is a upper case letter, redisplay the character in lower case If the character is a digit, display it…arrow_forward
- To receive an array argument, a function's parameter list must specify that the function expects to receive an array. The size of the array is not required between the array brackets. Select one: True O Falsearrow_forward// MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing #include <iostream> #include <string> using namespace std; int main() { // Declare variables string inCity; // name of city to look up in array const int NUM_CITIES = 10; // Initialized array of cities string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; bool foundIt = false; // Flag variable int x; // Loop control variable // Get user input cout << "Enter name of city: "; cin >> inCity; // Write your loop here // Write your test statement here to see if there is // a match. Set the flag to true if city is found. // Test to see if city was not found to determine if // "Not a city in Michigan" message should be printed.…arrow_forward// MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing #include <iostream> #include <string> using namespace std; int main() { // Declare variables string inCity; // name of city to look up in array const int NUM_CITIES = 10; // Initialized array of cities string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; bool foundIt = false; // Flag variable int x; // Loop control variable // Get user input cout << "Enter name of city: "; cin >> inCity; // Write your loop here // Write your test statement here to see if there is // a match. Set the flag to true if city is found. // Test to see if city was not found to determine if // "Not a city in Michigan" message should be printed.…arrow_forward
- // MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing #include <iostream> #include <string> using namespace std; int main() { // Declare variables string inCity; // name of city to look up in array const int NUM_CITIES = 10; // Initialized array of cities string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; bool foundIt = false; // Flag variable int x; // Loop control variable // Get user input cout << "Enter name of city: "; cin >> inCity; // Write your loop here // Write your test statement here to see if there is // a match. Set the flag to true if city is found. // Test to see if city was not found to determine if // "Not a city in Michigan" message should be printed.…arrow_forwardHomework - identical arrays for one-dimensional: Write a test program which prompts a user to enter the size of two arrays as well as to fill their elements. After that, the program checks the same contents of the elements of the two arrays. If these arrays are equal, the program displays message which is "The two arrays are identical". If not equal, displaying "The two arrays are not identical". Write an equals method that reads two arrays and displays these messages above.arrow_forward#include <stdio.h>int main(){int d;int s[20],i, j, p, lg=0,m,t=0;char c;printf("Enter number of sale: ");scanf("%d", &d);for(i=0; i<d; i++){ printf("\n sales %d sales: ",i+1);scanf("%d", &s[i]);}for(i=0; i<d; i++){for(j=i+1; j<d; j++){if(s[i] > s[j]){p= s[i];s[i] = s[j];s[j] = p;}}}printf("\n sales lowest to highest: ");for(i=0; i<d; i++){printf("\nsales %d ", s[i]);}printf("\n highest: %d ",t);getch();} it should be: highest : 2000arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage