why there's so many versions of c++ Hello World code and which one of them is correct?
There aren't that many. Correct are ones that output message similar to "Hello world!" to stdout.
If a piece of code does what it's supposed to do and it compiles, it's correct, you dumb shit.
>>55934136
Uh OP...that's C. And that's not even the standard. As of C89, it is no longer necessary to return an int as the compiler does that implicitly.
>>55934177
How does that make it not standard?
>>55934177
That has nothing to do with the standard, that's simply an implementation detail of the compiler.
The only correct ones are#include<stdio.h>
int main(void)
{
puts("Hello world!\n");
return 0;
}
and#include<iostream>
int main(void)
{
using namespace std;
cout << "Hello world!" << endl;
return 0;
}
>>55934224
Why correct using void into main parameter?
>>55934224
>puts and a \n
bruh...
>>55934364
'tism
>>55934136
Some are written in ways to save memory space.
>>55934400#include <iostream>
#include <vector>
int main()
{
char* s = "hello, world\n";
vector<char> v = new vector<char>(s, s + sizeof(s) / sizeof(char));
for (char *pc = v.begin(); pc < v.end(); pc++)
cout << *pc;
delete v;
}
>>55934577
*std::cout
*s + sizeof(s) / sizeof(char) - 1 (for null termination)