Arrays

Hello I am new in the forum and newbie in C++. Fist of all I whould like to thank Juan Soulie for the very helpful tutorial. Now my question, I want to have in a program an array and a function. The function have to take some values from tha array so tha array must be global variable and it's declaration will be out of the main function. And here is the problem, I don't know from the begining the size of the array. The size will be found in execution from a file which will be read in the main function.
Your help is wellcome, thank you.
Last edited on
Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int *a;//a pointer to the array

void function(){
	a[0]++;//do something with the array
}

int main(){
	int len;
	len=5;
	a=new int[len];//create the array
	a[0]=5;
	cout<<a[0]<<endl;

	function();
	cout<<a[0]<<endl;

	int i;cin>>i;
	return 0;
}


I hope it will help.
thank you hamsterman, your help and alex79roma's help in http://cplusplus.com/forum/beginner/88/ give me the solution.
Topic archived. No new replies allowed.