answersLogoWhite

0

What is array passer c plus plus?

Updated: 12/23/2022
User Avatar

Wiki User

11y ago

Best Answer

//Array Passer

//Demonstrates relationship between pointers and arrays

#include

<iostream>

using

namespace std;

void

increase(int* const array, const int NUM_ELEMENTS);

void

display(const int* const array, const int NUM_ELEMENTS);

int

main()

{

cout <<

"Creating an array of high scores.\n\n";

const

int NUM_SCORES = 3;

int

highScores[NUM_SCORES] = {5000, 3500, 2700};

cout <<

"Displaying scores using array name as a constant pointer.\n";

cout << *highScores << endl;

cout << *(highScores + 1) << endl;

cout << *(highScores + 2) <<

"\n\n";

cout <<

"Increasing scores by passing array as a constant pointer.\n\n";

increase(highScores, NUM_SCORES);

cout <<

"Displaying scores by passing array as a constant pointer to a constant.\n";

display(highScores, NUM_SCORES);

return

0;

}

void

increase(int* const array, const int NUM_ELEMENTS)

{

for

(int i = 0; i < NUM_ELEMENTS; ++i)

array

[i] += 500;

}

void

display(const int* const array, const int NUM_ELEMENTS)

{

for

(int i = 0; i < NUM_ELEMENTS; ++i)

cout <<

array[i] << endl;

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is array passer c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the lowest subscript of an array in c plus plus?

The lowest subscript of an array in C, or C++ is 0.


How do you declare a string array and add elements to it in C plus plus?

You cannot add elements to a fixed array in C or C++. If, however, the array is declared as a pointer to an array, you can add elements by allocating a new array, copying/adding elements as needed, reassigning the new array to the pointer, and deallocating the original array.


Array implementation of priority queue example program in c plus plus?

yes


What is multidimensional array in c plus plus?

A multidimensional array in C or C++ is simply an array of arrays, or an array of an array of arrays, etc. for however many dimensions you want. int a; // not an array int a[10]; // ten int a's int a[10][20]; // twenty int a[10]'s, or 200 int a's int a[10][20][30]; // and so on and so forth...


Is it possibly to return an array of strings in a function without using pointers in C plus plus?

No.


Can you help me with the C plus plus code of the program which has 10 index of array it adds 5 into every even elements of the array and then it subtracts 10 into the odd elements of the array?

int array[10] = {...}; for (int i = 0; i &lt; 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }


How do you make a C plus plus program that arrange the the numbers in ascending order?

Heres something i whipped up in a hurry... This uses the Bubble Sort method found (related links) #include &lt;iostream&gt; using namespace std; int main(int argc, const char* argv) { int arraysize = 5; //Unsorted array size int array [] = { 5, 3, 4, 2, 1 }; //The array of numbers itself //Display the unsorted array cout &lt;&lt; "Before: {"; for (int c=0; c &lt;= arraysize; c++) { cout &lt;&lt; array[c]; if (c != arraysize) { cout &lt;&lt; ","; } } cout &lt;&lt; "}" &lt;&lt; endl; //Acctually sort the array int tmp=0; //Used for swaping values for (int loop=0; loop &lt;= (arraysize - 1); loop++) { for (int c=0; c &lt;= (arraysize - 1); c++) //The sort loop { if (array[c] &gt; array[c + 1]) { //Swaps the two values in the array tmp = array[c]; array[c] = array[c + 1]; array[c + 1] = tmp; //Cleanup tmp = 0; } } } //Display the sorted array cout &lt;&lt; "After: {"; for (int c=0; c &lt;= arraysize; c++) { cout &lt;&lt; array[c]; if (c != arraysize) { cout &lt;&lt; ","; } } cout &lt;&lt; "}" &lt;&lt; endl; return 0; }


What is the difference between a C plus plus string and a C-style string?

A std::string is an object that encapsulates an array of type char whereas a C-style string is a primitive array with no members. A std::string is guaranteed to be null-terminated but a C-style string is not.


To find the largest element of an array in c plus plus?

int GetMaxElement( void * array) { if (array != 0) { return(max(array[], typeof(array))); } return(0); }


What has the author Harold C Passer written?

Harold C. Passer has written: 'The electrical manufacturers, 1875-1900'


What is syntax in c plus plus for declaring a variable?

type variable {[optional array size]} {= optional initializer};


What is an ordered list of data structure using c plus plus?

An ordered list of data in any programming language is simply a sorted array or list. In C++ this can either mean a sorted array, vector, list or forward list.