0
1

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 1 year has passed since last update.

引数名 引数名 : 引数型 で定義されてる関数って何やつ?(内部変数名と外部変数名のお話)

Last updated at Posted at 2022-08-11

1つ目の引数名:内部変数
2つ目の引数名:外部変数ってやつらしい

実装みてみる

例1)内部引数と外部引数が同じ場合(今まで見慣れた形はこれ)

    func fullName(firstName : String , lastName : String){
        print(lastName + firstName)
    }
    
    fullName(firstName: "Tomohiro", lastName: "Sasaki")

例2)内部引数と外部引数が異なる場合(引数名 引数名 : 引数型みたいになってるやつはこれ)

    func fullName(firstName first : String , lastName last : String){
        print(first + last)
    }
    
    fullName(firstName: "Tomohiro", lastName: "Sasaki")

関数内で利用する変数は内部引数。関数を実装する際に利用する変数は外部引数名
内部関数と外部関数を分けることで、「あれ、この関数実行するときに、引数名何渡せばいいんだっけか」という状況を回避できるっぽい。

0
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?