S
sumitverma1680
recently i came across this problem in one of C magzines, and it has
kept me wondering for some time.I am posting it here as i myself could
not figure it out ! any comments are most welcome.
I have tried MVC++ for general code test.
the problem is divided in two .c files as follow :
file1.c
#include <stdio.h>
extern void fn();
int arr[10] ;
int main()
{
fn();
}
file2.c
#include <stdio.h>
extern int *arr;
void fn()
{
arr[5]=5;
printf("%d",arr[5]);
}
when the above are compiled and linked there is no error . But during
de-referncing of arr ponter in fn() , memory acesss violation occurs?
can any body explain ? thanks in advance.
--- sumit ---
kept me wondering for some time.I am posting it here as i myself could
not figure it out ! any comments are most welcome.
I have tried MVC++ for general code test.
the problem is divided in two .c files as follow :
file1.c
#include <stdio.h>
extern void fn();
int arr[10] ;
int main()
{
fn();
}
file2.c
#include <stdio.h>
extern int *arr;
void fn()
{
arr[5]=5;
printf("%d",arr[5]);
}
when the above are compiled and linked there is no error . But during
de-referncing of arr ponter in fn() , memory acesss violation occurs?
can any body explain ? thanks in advance.
--- sumit ---