And now you have a declaration of x at the top of the program and a definition at the bottom. But usually extern is used when you want to access a global variable declared in another source file, as I showed above, and then link the two resulting object files together after compilation....
Once something is defined, that also counts as declaring it; so you can often both declare and define a funtion, class or variable at the same time. But you don't have to. For example, having a declaration is often good enough for the compiler. You can write code like this: ...