+ 14
How to write a Hello World program without main method?
Any type of functions to use instead of main?
16 Réponses
+ 44
Try this (C++).
#include <iostream>
#define hello ma##in
using namespace std;
class HelloWorld {
public:
HelloWorld() {
cout << "Hello World!";
}
}world;
int hello() {
return 0;
}
+ 8
thank you for your Explanation
+ 7
But can u alias the main method?
+ 7
Open notepad and type Hello World. Save it. Now when you want to run the program, just click on the document and it'll tell you Hello World. However, I have to let you know, that's just an illusion because notepad has a main method, just like any other program I've seen.
+ 4
Without a main method the program wouldn't know where to start.
+ 2
Maybe I didn't understand your point, but
you can write it in an interpreted language.
Python: Write file 'Hello_World.py' with content:
print("Hello World")
0
It's useful to know what main is. it's just a calling convention used by several programming languages to provide a label that can be used to indicate an entry point for a program that gets inserted into memory and executed. There are other ways to jump to addresses for execution as well. For example, if you look at software for a microcontroller, you'll find a vector table which likely starts at address 0 and goes up a few hundred bytes, arranged in small blocks that each jump to another point in memory. The purpose of this table is to respond when interrupts are triggered.
So I can write a small program that sends "hello world" to a serial device or something that is triggered by a button push. I don't need a main function, but I do need to write the vector table into memory and run the processor from the reset vector.
The vector table is almost guaranteed to be written in assembler specific to the processor. Once the processor has code to start up, I'd switch to C unless I had a very good reason. Once I'm in C, I'll almost always start with main.
0
. VBS
0
using php you can print hello world just using
echo "hello world";
- 1
FOR JAVA
IF JDK Version is less than 5, then
class TestClass {
static {
System.out.println("hello world");
}
}
if JDK version is greater than 6 -
class TestClass {
static {
System.out.println("hello world");
}
public static void main(String... s) {
}
}
- 1
you need python ....
- 1
what for?
- 1
In Python, just type print("hello world"). The output will be ' hello world'
- 2
Use static key word if you're coding in Java then call the non-main method in using the class name with the dot operator, e. g ClassName.methodName()
- 2
Use any programming language that doesn't use a method named "main" as the executive part of the program.
- 4
main is not really a function type it's a function name , u don't have to use any function u can directly cout<<"hello world";