For gcc there's a non-standard solution. Declare the function with __attribute__((constructor)) (note the double parentheses).
Like this:
void init(void) __attribute__ ((constructor));
void init(void) {
// your code goes here
}
Starting with gcc 4.3 there's even a possibility to assign a priority to the "constructor". See http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html for details.
Every C plus plus program that is a main program must have the function 'main'.
No. Neither C nor C++ are interpreted. Both need to be compiled and linked to produce highly-optimised machine code, which is then executed.
There is no such thing. You probably meant the main function. The main function is the only function that is required as it serves as the entry point of the program.
Anything declared outside of a function is global.
Abstraction is a process by which higher concepts are derived from the usage and classification of literal ("real" or "concrete") concepts, first principles and/or other abstractions.
It is the first function that gets called when the program is executed.
Every C plus plus program that is a main program must have the function 'main'.
No. Neither C nor C++ are interpreted. Both need to be compiled and linked to produce highly-optimised machine code, which is then executed.
There is no such thing. You probably meant the main function. The main function is the only function that is required as it serves as the entry point of the program.
Anything declared outside of a function is global.
Functions are very important in C++, as you can't write the simplest program to print hello without using a function. Overall you can say that function are building blocks of a C++ program. Functions can also be defined by the programmer to reduce program size.
I don't think its possible. Every C++ program must at least have the main function.
Abstraction is a process by which higher concepts are derived from the usage and classification of literal ("real" or "concrete") concepts, first principles and/or other abstractions.
By learning how to program on C+.
If you are talking about the program executing, but the output screen being displayed for a flash and then disappearing, I suggest adding getch() or getchar() function at the end of your main function. This will make sure that the output screen waits for you to press a character before the program terminates.
In C and C++, as well as in many (all?) languages, a function can be called from more than one place in a program. That's the purpose of functions - to encapsulate pieces of code that are needed in more than one place in the program.
The format of a basic C++ program is as follows: First, you have your include statements. Next, you have your function prototypes, and class declarations. Then, you have your main function. This can be organized into small parts using whitespace characters. Finally, you have the definition of all the functions you call in the main function. Really, it's up to the individual programmer how most of the code is organized, but the above is a good structure if you're not absolutely sure what you're doing.