Program to run code without main()

11 months ago Admin 0

Run code without main()

This article illustrates the concept how to run code without main() in c/c++.

run code without main()

Here is the source code and output of both the programs.

C Programming language

Program


#include<stdio.h>
#define run main
void run()
{
 printf("Welcome to Snapcout");
 getch();
}

After successfully compiling and executing the above C program,output is:-

run code without main()


C++ Programming language

Program


#include<iostream.h>
#include<conio.h>
#define run main
void run()
{
 cout<<"Welcome to Snapcout!!";
 getch();
}

After successfully compiling and executing the above C++ program,output is:-

run code without main()


Comment below if you are facing any problem or you find any error in the above program and also subscribe to our newsletter for more updates.


Read more c/c++ Programs published by snapcout:-

Program to call main() function in main()
Program to execute both if and else statements simultaneously
Program to find greatest between two numbers without using if else
Program to print hello world without using semicolon
https://snapcout.com/reverse-an-entered-alphabet/


About article

Written By:- Admin

Published on:- 21/09/2018

Published By:- Snapcout


Don't forget to share the article if you like it:-