![]() |
Arrays or Vectors?
I have seen a lot of debate on wheather to use arrays or vectors for passing arrays in functions. I have a simple program here that does not quite seem to work properly as what I intended. The goal is to take the arrays from f1() and f2() and pass all the elements to the main where the elements are added togethor. I get a "segmentation fault" error.
How would I use vectors as an alternate to arrays? :
Thanks if anyone can clarify this. :banana: |
Use a pointer.
And pass the array through the function. :
void func(double *table, int len) |
The seg fault is caused by a1 and b1 being used to index an array before they have been initialized to a value within the valid range.
Here is a vector version of your code. I've not changed any logic, so if the output isn't what you expected, that's your fault:D :
#include <iostream> |
| All times are GMT -5. The time now is 5:01 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC