Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



   2266

C++ FUNCTION TO TAKE ARRAY VARIABLE AS AN ARGUMENT (NEED UR HELP ASAP)!!

by kazmi99 - 01 February, 2023 - 01:48 PM
This post is by a banned member (kazmi99) - Unhide
kazmi99  
Registered
163
Posts
25
Threads
3 Years of service
#1
(This post was last modified: 01 February, 2023 - 01:48 PM by kazmi99.)
PEACE BE UPON ALL THE READERS
I am stuck at this problem very bad!
I need to write a C++ function that takes an array variable as an argument.
BUT I AM STUCK!!
Please let me know if you could help me!
ThankYou!

This is a bump
It's chewsday init
This post is by a banned member (Druskiiii7) - Unhide
This post is by a banned member (kazmi99) - Unhide
kazmi99  
Registered
163
Posts
25
Threads
3 Years of service
#3
(01 February, 2023 - 01:48 PM)Gotz Wrote: Show More
post ur code here  ?

I have not started to code it yet....
Could you please help me write this function form the scratch?
It's chewsday init
This post is by a banned member (HowNiceOfYou) - Unhide
This post is by a banned member (kazmi99) - Unhide
kazmi99  
Registered
163
Posts
25
Threads
3 Years of service
Bumped #5
This is a bump
It's chewsday init
This post is by a banned member (kazmi99) - Unhide
kazmi99  
Registered
163
Posts
25
Threads
3 Years of service
Bumped #6
This is a bump
It's chewsday init
This post is by a banned member (noarch) - Unhide
noarch  
Supreme
544
Posts
300
Threads
#7
(01 February, 2023 - 01:48 PM)kazmi99 Wrote: Show More
PEACE BE UPON ALL THE READERS
I am stuck at this problem very bad!
I need to write a C++ function that takes an array variable as an argument.
BUT I AM STUCK!!
Please let me know if you could help me!
ThankYou!

This is a bump
Code:
[color=#3498db]printArray[/color]
function takes two arguments: an array
Code:
[color=#3498db]arr[/color]
and an integer
Code:
[color=#3498db]size[/color]
. The function loops through the elements of the array using a for loop and prints each element to the console. The
Code:
[color=#3498db]main[/color]
function creates an array
Code:
[color=#3498db]arr[/color]
and calls the
Code:
[color=#3498db]printArray[/color]
function to print the elements of the array to the console.
 
Code:
 
#include <iostream>

using namespace std;

void printArray(int arr[], int size) {
  for (int i = 0; i < size; i++) {
    cout << arr[i] << " ";
  }
  cout << endl;
}

int main() {
  int arr[] = {1, 2, 3, 4, 5};
  int size = sizeof(arr) / sizeof(arr[0]);

  cout << "The array is: ";
  printArray(arr, size);

  return 0;
}
This post is by a banned member (noarch) - Unhide
noarch  
Supreme
544
Posts
300
Threads
#8
(This post was last modified: 03 February, 2023 - 09:23 AM by noarch. Edited 2 times in total.)
There is a code posted above from a banned user but there is no comment on how the code works.
Code:
 
In this example, the
[code]
printArray
function takes two arguments: an array
Code:
arr
and an integer
Code:
size
. The function loops through the elements of the array using a for loop and prints each element to the console. The
Code:
main
function creates an array
Code:
arr
and calls the
Code:
printArray
function to print the elements of the array to the console.
[/code]

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 2 Guest(s)