hi all
Code:
#ifndef _HEADER_FILE_H
#define _HEADER_FILE_H
extern int x;
#endif
Code:
header_file.c
include "header_file.c"
int x;
main.c
Code:
#include<stdio.h>
#include "header_file.h>
int main()
{
x=55;
printf("%d\n",x);
return 0;
}
now what is the question ?
the question in the variable x ;
it's declared in the header_file
the defined in the header_file.c
then used in the main.c
but what if i redefined it in main.c also like that
main.c
Code:
#include<stdio.h>
#include "header_file.h>
int main()
{
int x=55;
printf("%d\n",x);
return 0;
}
i tried and it work
so my question is ?
what has happen to the variable x in the header_file.c when i redefined the variable x in main .c again ?
and
i cannot allocate space like that
Code:
/*header*/
#ifndef _SS_H
#define _SS_H
extern int comp;
extern char* all;
#endif
Code:
/*header source*/
#include "ss.h"
#include<stdlib.h>
int comp=14;
char *all=malloc(100*sizeof(*all));
error :ss.c:5: error: initializer element is not constant
so my question is why i cannot allocate space like that?
thanks