ADVERTISEMENT
ADVERTISEMENT

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.