Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ Pass Array to a Function

void myFunction(int myNumbers[5]) {
  for (int i = 0; i < 5; i++) {
    cout << myNumbers[i] << "
";
  }
}

int main() {
  int myNumbers[5] = {10, 20, 30, 40, 50};
  myFunction(myNumbers);
  return 0;
}
Comment

passing array to the function c++

double getAverage(int arr[], int size) {
  int i, sum = 0;       
  double avg;          

   for (i = 0; i < size; ++i) {
      sum += arr[i];
   }
   avg = double(sum) / size;

   return avg;
}
Comment

passing array to the function c++

void myFunction(int param[]) {
   .
   .
   .
}
Comment

passing array to the function c++

//passing array as a pointer.
void myFunction(int *param) {
   .
   .
   .
}
Comment

passing array to the function c++

void myFunction(int param[10]) {
   .
   .
   .
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: sizeof’ on array function parameter ‘arr’ will return size of ‘int*’ [-Wsizeof-array-argument] 
Cpp :: concatenate two vectors c++ 
Cpp :: how to print a text in c++ 
Cpp :: See Compilation Time in c++ Program 
Cpp :: c++ insert into map 
Cpp :: cin getline 
Cpp :: unique_ptr syntax 
Cpp :: length of string in c++ 
Cpp :: arduino xor checksum 
Cpp :: c++ int length 
Cpp :: reverse sort a vector 
Cpp :: remove first occurrence of value from vector c++ 
Cpp :: factorial calculator c++ 
Cpp :: c++ char array size 
Cpp :: c++ looping through a vector 
Cpp :: length of array c++ 
Cpp :: demonstrate constructor 
Cpp :: accumulate() in c++ 
Cpp :: c++ for loop multiple variables 
Cpp :: char to string c++ 
Cpp :: system("pause") note working c++ 
Cpp :: how to initialize a queue in c 
Cpp :: c++ vector 
Cpp :: udo apt install dotnet-sdk-5 permission denied 
Cpp :: fill vector with zeros c++ 
Cpp :: C++ linked list iterator 
Cpp :: matrix c++ 
Cpp :: size of string c++ 
Cpp :: c++ call by value 
Cpp :: integer max value c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =