Rust program to create a simple function

Rust | Function Example: Write an example to create a simple function. Here, we will write a function to print "Hello World".
Submitted by Nidhi, on October 06, 2021

Problem Solution:

In this program, we will create a user-defined function SayHello() to print the "Hello World" message.

Program/Source Code:

The source code to create a simple function is given below. The given program is compiled and executed successfully.

// Rust program to create a 
// simple function

fn SayHello(){
    println!("Hello World");
}

fn main() {
    SayHello();
}

Output:

Hello World

Explanation:

In the above program, we created two functions SayHello() and main(). The SayHello() function is a user-defined function to print the "Hello World" message.

In the main() function, we called SayHello() function and printed the "Hello World" message.

Rust Functions Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.