0
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?

More than 3 years have passed since last update.

各言語の便利な機能のメモ

Posted at

複数のプログラミング言語でコードを書いていると、忘れてしまうので備忘録
※文法エラーはご容赦ねがいます。

スプレッド演算子

複数の引数を取る関数に配列の内容を渡したいときに利用する。
工夫次第でコードを短くできるのが嬉しい機能。

C言語の場合

そんな機能はないのでゴリゴリ書く。

void handler(int p1, const char* p2) {
    printf("%d, %s", p1,p2);
}
	
handler(list[0], list[1]);

TypeScriptの場合

function handler(p1 :number, p2:string) {
    console.log("test", p1, p2)
}
const list= [ 1000, "12345" ] as const
handler(...list)

Pythonの場合

def handler(p1, p2):
    print(p1,p2)
	
list = [1000,"1234"]
handler(*list)
0
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
0
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?