 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write a running C code without main()?
Here we will see, one program can be written without main or not? The answer is yes. We can write program, that has no main() function.
In many places, we have seen that the main() is the entry point of a program execution. Just from the programmers perspective this is true. From the system’s perspective it is not true. So the system at first calls the _start(), this sets up the environment, then main is called.
To execute this program we have to use this option ‘-nostartfiles’.
Example
#include <stdio.h> extern void _exit(register int); int _start() {    printf("Program without main
");       _exit(0); }  Output
soumyadeep@soumyadeep-VirtualBox:~/Cpp_progs$ gcc test_prog.c -nostartfiles soumyadeep@soumyadeep-VirtualBox:~/Cpp_progs$ ./a.out Program without main soumyadeep@soumyadeep-VirtualBox:~/Cpp_progs$
Advertisements
 