Rust program to create string literals

Here, we are going to learn how to create string literals in Rust programming language?
Submitted by Nidhi, on September 22, 2021

Problem Solution:

Here, we will create string literals using &str type. The value of string literal is known at compile time.

Program/Source Code:

The source code to create string literals is given below. The given program is compiled and executed successfully.

// Rust program to create string literals

fn main() {
    let name:&str   ="rocky";  
    let company:&str="includehelp";  
    let address:&str="New Delhi India";  
    
    println!("Name          : {}",name);
    println!("Company Name  : {}",company);
    println!("Address       : {}",address);
}

Output:

Name          : rocky
Company Name  : includehelp
Address       : New Delhi India

Explanation:

Here, we created 3 string literals using &str type. Then we printed the values of created string literals.

Rust Basic Programs »



Related Programs



Comments and Discussions!

Load comments ↻





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