I have a problem with a shared variable. I compile all the files and first run server.c
and second run client.c
. This is my file server.c
:
#include "server.h"
int port;
int main()
{
port = 4;
}
This is my file server.h
:
int port;
This is my file client.c
:
#include <stdio.h>
#include "server.h"
extern int port;
int main()
{
printf("PORT is %d\n", port);
}
The output is
PORT is 0
Why is the number not 4?