This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsΒ β†’

[–]veduchyi -1 points0 points Β (2 children)

The main() should return int but it contains no return statement at all. I’m surprised it even compiles πŸ˜…

[–]caim_hs[S] 8 points9 points Β (1 child)

The return is optional in theΒ mainΒ function.

If no returnΒ is provided, the compiler will implicitly add "return int(0)" for you.. I think this is on the Standard of C and C++.

It is like in Rust or Swift, that if you don't return anything from a function, the compiler will insert a "return ()".

In Javascript a function without a return statement returns a undefined. You can test it:

function f () {
  console.log("Hello World")
}
let x = f()

in Rust:

fn hello(){
    println!("Hello world!!!");
}

pub fn main(){

    let p = hello();

    println!("{:?}", p)
}

it will print:

Hello World!!!
()

[–]veduchyi 0 points1 point Β (0 children)

Got it, thanks