function and array!?

Well i not really sure how to use function so here is my question. I got and array
and i declared it in a function but then my main program got code that required the array from my function but it couldn't detect it and pop up weird number so can help me explain how really function works for array? And what is the differences between void func() and int func() ?

here is a small example of my func()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
void func();
void main()
{
	int num[4][4];
	int row,col;
func();

for(row=0;row<4;row++)
{
for(col=0;col<4;col++)
{
printf("%d ",num[row][col]);
}
printf("\n");
}
}

void func()
{
int num[4][4];
int row,col;

for(row=0;row<4;row++)
{
for(col=0;col<4;col++)
{
scanf("%d ",&num[row][col]);
}
printf("\n");
}
}
The place where the memory is kept is different

Just put the array in global.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int num[4][4];

void func(){

int row, col;

for(row=0;row<4;row++)
{
for(col=0;col<4;col++)
{
scanf("%d ",&num[row][col]);
}
printf("\n");
}

}

int main(){

int row,col;
func();

for(row=0;row<4;row++)
{
for(col=0;col<4;col++)
{
printf("%d ",num[row][col]);
}
printf("\n");
}

return 0;

}



Sorry, if I type wrong, I haven't tried to compile it yet.
See, if you write a function which will take an array or a variable or anything and then use it then you have to give the arguement in the function defination. For example let there be a function for insertion sort.
void InsSort(int AR[], int size)
{
//code
}

and in the main you input an array of 10 random numbers in array[100] and the size(i.e 10) is stored in n and you want to sort it, then in main call the function in the following way
InsSort(array,n)
thx! i got it now
Topic archived. No new replies allowed.