I'd be itnerested in where you have been learning the language, you've obviously learned some strange things --
It is perfectly conventional to define/declare variables that are local to the a function
Code:
int main()
{
int a; int b; // variables declared in main
a = b = 0; // initialize them!
}
even if it is main. You can not define functions within the main function (however you can declare them)
Code:
int main()
{
// error C2601: 'sub' : local function definitions are illegal
int sub()
{
return bar;
}
// declares that a function 'foo' exists and shall be resolved by the linker
int foo();
}
You can also define and declare variables outside of main (in functions other than main or global variables)
Code:
#include <stdio.h>
int a = 0, b = 0; // global variables
void bar(); // regular function declaration
int main()
{
void foo(); // this is weird to declare function inside of main
foo();
bar();
}
void foo()
{
a = b = 1;
}
void bar()
{
printf("%d %d", a, b);
}