Question

1. Write a C++ Program to display address of elements of an array using both array...

1. Write a C++ Program to display address of elements of an array using both array and pointers

2. Write a C++ Program to insert and display data entered by using pointer notation.

3. Write a C++ Program to access Array Elements Using Pointer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

CODE

#include <iostream>

using namespace std;

int main() {

float arr[5];

cout<<"Displaying address using array notation: "<< endl;

for (int i = 0; i < 5; ++i) {

cout << &arr[i] <<endl;

}

cout<<"Displaying address using pointers notation: "<< endl;

for (int i = 0; i < 5; ++i) {

cout << arr + i <<endl;

}

return 0;

}

2)

CODE

#include <iostream>

using namespace std;

int main()

{

int data[5];

cout << "Enter elements: ";

for(int i = 0; i < 5; ++i)

cin >> *(data+i);

cout << "You entered: ";

for(int i = 0; i < 5; ++i)

cout << endl << *(data + i);

return 0;

}

3)

CODE

#include <iostream>
using namespace std;

int main()
{
   int data[5];
   cout << "Enter elements: ";

   for(int i = 0; i < 5; ++i)
      cin >> data[i];

   cout << "You entered: ";
   for(int i = 0; i < 5; ++i)
      cout << endl << *(data + i);

   return 0;
}

Output

Enter elements: 1
2
3
5
4
You entered: 1
2
3
5
4
Add a comment
Know the answer?
Add Answer to:
1. Write a C++ Program to display address of elements of an array using both array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Pointer tasks: ( In C++ ) 1. Write a program to store the address of a...

    Pointer tasks: ( In C++ ) 1. Write a program to store the address of a character variable and a float variable. • Print the address of both variables. • Print the values of variable using dereference operator. • Add 2 in float value using pointer. • Print address of character variable using reference operator. 2. Write a program that takes 5 elements in an array and print them in reverse order using pointers. 3. Write to program that takes...

  • C++. Write a program that copies the contents of one array into another array but in...

    C++. Write a program that copies the contents of one array into another array but in reverse order using pointers.           - in main()                    - define 2 arrays of type int, 10 elements each                              - initialize one array with numbers 1 through 10                              - initialize all elements of the second array to 0                    - call function reverseCopy with both arrays as arguments                    - display the values of array number 2 (reversed order)           - reverseCopy...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • Write a C++ program that will create an array with a given number of elements. Use...

    Write a C++ program that will create an array with a given number of elements. Use size = 10 for demonstration purposes, but write the program where the size of the array can be changed by changing the value of one constant. Fill the array with random numbers between 0 and 100. Write the program to perform the following operations: 1. Find and display the largest value in the array. 2. Find and display the smallest value in the array....

  • Here's an assignment that'll give you some practice with pointers. All you have to do is...

    Here's an assignment that'll give you some practice with pointers. All you have to do is write a program that allows the user to populate an array of doubles (5 values) by calling the function InitArray. After the user has entered all the values, then call the function DispRevArray to display the array in reverse. Main will create and allocate space for an array of type double for 5 elements. Then you will create and allocate a pointer that will...

  • Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the...

    Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the user to enter a number and based on the entered number it allocates the array size. Then based on that number it asks the user that many times to enter student’s names. What you need to do:  Add another array of doubles to store the gpa of each student as you enter them  You need to display both the student’s name and...

  • 8. (15 marks) Write a complete C program, which uses an array of structures and two...

    8. (15 marks) Write a complete C program, which uses an array of structures and two user defined functions. The program deals with a library database. The program will ask the user to input required information about each book and store it in a structure in a user defined function called get info. The second user defined function display_info will display database information on the screen. The output should look as follows: Book Title Book ld 123456 C Programming 10...

  • need question 3 assap using cin and cout outputs please Ctrl CSC 270 Final Exam-Spring2 1) [10 pts] Create anarray x which includes integers fron ltos obtain the array y which, even formula. Displ...

    need question 3 assap using cin and cout outputs please Ctrl CSC 270 Final Exam-Spring2 1) [10 pts] Create anarray x which includes integers fron ltos obtain the array y which, even formula. Display both arrays x and y in a table with labeled column headings. 0 y- 2x+1 2) 120 pts] Consider the following 2D array. 01 2 -1 X-3 5 0 6 -3 7 -15 Use the standard notation and obtain the following (a) Create and display array...

  • Need help with these, especially number 4. C++ program L. WIite the function Write a function...

    Need help with these, especially number 4. C++ program L. WIite the function Write a function mpgcalculator that accepts pointers to three arrays. The firstis an array of miles, the second is an array of gallons, the third will hold mile-per-gallon. It has no return value. 4. a. b. c. d. write the prototype call this function with these three arrays: miles, gallons, mpg. write the function use only array notation 5. Do #4, using only array with offset notation....

  • Write a small program that uses a function to add array elements from an array into...

    Write a small program that uses a function to add array elements from an array into a linked list in-order. Use the following array: const int size=5; int arr[size] = { 4, 1, 7, 2 ,3 }; Output: Array out of order: 4 1 7 2 3 Array in order using Linked List : 1 ,2, 3, 4, 7 Your program should display the linked list in-order using the array given.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT