Skip to content

Instantly share code, notes, and snippets.

@alchem0x2A
Created April 20, 2018 14:59
Show Gist options
  • Save alchem0x2A/d813517bbb8f7f08dd9f38ab9cfd66a0 to your computer and use it in GitHub Desktop.
Save alchem0x2A/d813517bbb8f7f08dd9f38ab9cfd66a0 to your computer and use it in GitHub Desktop.
Right Handle of Array Point with function
#include <iostream>
// Return vector y = x * x
void manipulate(double *y, double *x, size_t n){
/* x and y must be initialized! */
std::cout << "Inside the function" << std::endl;
std::cout << "Size of x?: " <<
sizeof(x) << " "
<< "Size of y?: "
<<sizeof(y)
<< std::endl;
for (size_t i=0; i< n; ++i)
y[i] = x[i] * x[i];
}
int main() {
double y[5];
double x[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
std::cout << "In the main function" << std::endl;
std::cout << "Size of x?: " << sizeof(x) << " "
<< "Size of y?: "<< sizeof(y)
<< std::endl;
manipulate(y, x, 5);
std::cout << "x is:" << std::endl;
for (size_t i=0; i< 5; ++i)
std::cout << x[i] << " ";
std::cout << std::endl;
std::cout << "y is:" << std::endl;
for (size_t i=0; i< 5; ++i)
std::cout << y[i] << " ";
std::cout << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment