What happens if I declare another variable with the same name in another file?

I declared one int xin the file and by mistake I declared another variable of the type charwith the same name xin file two , and I am waiting for the compiler or linker to inform me of the error, but the errors do not appear. and when I use the debugger, I see what int xconverts to char x, is that true ?! and what is really going on here ?!

Show this modification in my code:

One File

#include <stdio.h>

int x = 50;  /** declare global variable called
                           x **/
int main()
{
    print();
    printf("      global in file one = %d",x);  /** Modification is just here **/
    return 0;
}

File 2

char x;   

void print(void)
{

    x = 100;
    printf("global in file two = %d ",x);
    return;

}

My expected results = global in file two = 100 global in file one = 50

but the results: global in file two = 100 global in file one = 100

, , int x char x, ?! ?

+4
1

. undefined. char x - , . , int x . , , , , . , x, , (, , ).

, , static, .

+5

All Articles