• Register
1 vote
27 views

Problem:

Hello good people,

I am a new student of programming. One of my friends inspired me to learning programming and I took up the C++ language. My friend said it is easy to grab and I accept his words.

Anyway, I am in the chapter of the array now. I learned the basic things of the array and its characteristics. I want to know the process of an array printing in a C++ program. Please, write me a code that prints array and keep your program as easier as possible. Thanks for your concern.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

There are several ways to print an array in C++. The simplest way is using the array indices. You can run an iteration through the array size and print each value of it.

#include <iostream>
int main(){
	int array[] = { 1, 2, 3, 4, 5 };
	size_t n = sizeof(array)/sizeof(array[0]);
	for (size_t i = 0; i < n; i++) {
		std::cout << array[i] << ' ';
	}
	return 0;
}

The other methods are pretty advance. You’ll learn those methods and their usage by the time soon. Keep learning and aking.

Good Day!

13 9 6
94,260 points

Related questions

0 votes
1 answer 23 views
23 views
Problem: My code asks for data and fills it to the array. Then check if they are even. And it should print the data which is even. The data filling if you do it correctly. But at the time of printing I only get this - The number 0 in position [0] is even #include <iostream> using namespace std; int ... { cout << "The number" << * p ++ << "in position [" << i << "] is even \ n"; } } return 0; }
asked Dec 5, 2020 sasha 16.2k points
0 votes
1 answer 16 views
16 views
The program works up to 3 for but from the fourth the search for the minor / s and the major / s begins, which I managed, but if the value is repeated (which is the lowest or highest ), thus having 2 (or more) minors or majors, it only prints the one below the entered ones. So the question is ... << << "is the one with the fewest days left" << "(" << less << ")" << endl; cout << endl; return 0; }
asked Aug 14, 2020 game 4.6k points
0 votes
1 answer 2 views
2 views
Problem: How to print 2D Arrays in C++?
asked 1 day ago Humaira ahmed 23.4k points
0 votes
1 answer 4 views
4 views
Problem I want to make a function that prints the value of array in c++
asked Apr 5 Subhendu 4.5k points
0 votes
1 answer 1 view
1 view
Problem: How do we pass an array as an argument to a function?
asked 15 hours ago Humaira ahmed 23.4k points
0 votes
1 answer 1 view
1 view
Problem: I'm trying to read numbers from a text file into an array. The text file, "somenumbers.txt" simply holds 16 numbers as so "5623125698541159". Please help.
asked 3 days ago muktaa 10.8k points
0 votes
1 answer 4 views
4 views
Problem: How to copy a char array in C?
asked 5 days ago Humaira ahmed 23.4k points
0 votes
1 answer 3 views
3 views
Problem: There is some problem with this. Does anyone know how to make a pointer to an array c++?
asked Apr 10 anika11 10.1k points
0 votes
1 answer 3 views
3 views
Problem: I am stuck during learning as I have already mentioned in my question someone please cooperate me to continue my project-Thanks
asked Mar 24 rubelkhan 20.4k points
0 votes
1 answer 6 views
6 views
Problem: I will request someone to answer my question Please, I have searched on the web but I got no useful information for this, now I am in difficulty continuing my learning
asked Mar 21 rubelkhan 20.4k points