i wanna put all my variable initialization at a header file..
but after i put in a header file name, "variable.h"

i #include "variable.h" in main. but it still cant reconize the variable.
what can i do? + extern infront all the variable in header file?

you don't initialize variables in header files becuse the variables don't exist. You have to declare variables in *.c or *.cpp files. You can, however, use the extern keyword with variable in header files, but again they can not be initialized there.

// myheader.h file
extern int myint;

Then in one, and only one, *.cpp file you declare the same variable but without extern keyword. You can also initialize it then.

// myprogram.cpp
#include "myheader.h"

int myint = 0;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.