why this output in multiprogramming C :     #include<stdio.h>
    #include<pthread.h>
    #define NUM_THREAD (5)
    
    int sum=0;
    void* runner(void * param);
    
    int main(int argc,char **argv){
    
    	pthread_t tid[NUM_THREAD];
    	pthread_attr_t attr;
    	
    	for(i=0;i<NUM_THREAD;i++){
    	pthread_create(&tid[i],&attr,runner,NULL);
    	}
    	for(i=0;i<NUM_THREAD;i++){
    	pthread_join(tid[i],NULL);
    			}
    	printf("After threading %d",sum);
    	return 0;
    }
    
    
    void * runner(void *param){
    	for(int j = 0;j<10;j++)  sum+=j;	
    	pthread_exit(0);
    
    }

**output**: 225


In the following code, the output is 225. But the correct should be 45

I know threads share global variables!. so this function should correctly ouput right. But adding that sum=0 inside only gives correct output.  Whats happening here i dont understand! 

    void * runner(void *param){
    sum=0;   // MY DOUBT 
    for(int j = 0;j<10;j++)  sum+=j;	
    	pthread_exit(0);
    
    }

**output**: 45