1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paiza.ioでrust その11

Posted at

概要

paiza.ioでrustやってみた。
練習問題やってみた。

練習問題

関数を使え。

サンプルコード

fn hello_world1() -> String {
	return "Hello world1".to_string();
}
fn hello_world3() -> &'static str {
	return "Hello world3";
}
fn foo() -> String {
	String::from("foo!!")
}
fn append_world(str: &mut String) {
  str.push_str(" World");
}
fn concat_reference(a: &String, b: &String) -> String {
	let c: String = format!("{} {}", a, b);
	c
}

fn main() {
	println!("{}", hello_world1());
	println!("{}", hello_world3());
	println!("{}", foo());
    let mut str = "Hello".to_string();
    append_world(&mut str);
    println!("{}", str); 
    println!("{}", concat_reference(&str, &str)); 
}




実行結果

Hello world1
Hello world3
foo!!
Hello World
Hello World Hello World

成果物

以上

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?