Code::Blocks is not a compiler, but an IDE.
How to compile and run a C file in CodeBlocks which is outside a project?
It runs compilation commands, probably using GCC (but consider also Clang). It is the compiler which compiles your code (not CodeBlock).
So you don't compile with CodeBlocks.
(BTW, remove gcc on your system, and CodeBlocks become useless to build any program -both inside a project or single file- from C code)
To compile foo.c into some program fooprog you want to run something like
gcc -Wall -Wextra -g foo.c -o fooprog
and you may want other arguments to gcc (e.g. some -I or -D for preprocessing, some -L or -l for linking libraries). Their order is important. Read chapter on invoking GCC. The -Wall -Wextra asks for all warnings and more of them. The -g asks for debug information. The -o fooprog requires to output the executable fooprog... Details could be operating system specific.
You can run that gcc command in a terminal. Perhaps CodeBlock could be configured to run it somehow (that is a very different question).
You could also learn more about build automation. Consider GNU make or ninja, etc... Your Makefile might build several executables (with a plain make command, and you could configure your IDE or editor to run it).
Notice that many free software projects (on github, sourceforge, etc etc...) are not requiring any particular IDE (but are built using some build automation software). That could ring bells in your head. Good source code editors (such as emacs or vim) are able to run build commands (as nicely, and more generally, than IDEs). Perhaps you should consider using them.