Q:

Rust program to create string literals

belongs to collection: Rust Basic Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to print the length of string literal... >>
<< Rust program to create an alias of built-in data t...