How to use extern variable to share variables between source files in C

1 Answer

0 votes

file: test.h

extern int extern_n; // Declaration 

file: test.c

#include "test.h"

extern_n = 100;

file: example.c

#include <stdio.h>

#include "test.h"

int main(int argc, char **argv) 
{ 
    printf("%d", extern_n);
    
    return 0; 
}


/*
  
run:
   
100

*/


 



answered Oct 29, 2015 by avibootz
edited Nov 1, 2015 by avibootz

Related questions

...