Elinore wrote:
> hi
>
> I am practicing whole structure passing.
> Array 'c' add two arrays 'a' and 'b' in 'sum' function..
> Result is okay, but see segmentation fault (core dumped). Can anyone
> help me with this? Thanks
>
>
> #include <stdio.h>
> #include <time.h>
>
> #define N 10
> #define Rand_MAX 5
>
> struct par{
> int a[N];
> int b[N];
> int c[N];
> };
> void sum(struct par *);
>
> main()
> {
> int i;
> struct par *inte;
`inte' is a variable that can point to `struct par'
objects. Fine. However, `inte' has not been given any
value yet, so (just like `i') its value is indeterminate;
it's a "garbage pointer."
> srand((unsigned)time(NULL));
>
> for(i=0;i<N;i++){
> inte->a[i] = (int)rand() % Rand_MAX;
.... and here you use the "garbage pointer" to reference
the non-existent `struct par' object that it doesn't
point to. All bets are off; anything at all can happen.
If you're lucky, your program will crash.
> [remainder snipped, and not examined for further trouble]
--