The source code to create the alias of a structure is given below. The given program is compiled and executed successfully.
// Swift program to create an alias of a structure
import Swift
struct Person
{
var id: Int
var name: String
}
typealias Student = Person
var S = Student (id: 101, name: "virat")
print("Student id: \(S.id)" )
print("Student name: \(S.name)")
Output:
Student id: 101
Student name: virat
...Program finished with exit code 0
Press ENTER to exit console.
Explanation:
In the above program, we imported a package Swift to use the print() function using the below statement,
import Swift
Here, we created a structure Person that contains two members id and name. Then we created the alias name Student of structure Person using the "typealias" keyword. After that, we created the object of structure using the Student alias and initialized and print the value of the structure.
Program/Source Code:
The source code to create the alias of a structure is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we imported a package Swift to use the print() function using the below statement,
Here, we created a structure Person that contains two members id and name. Then we created the alias name Student of structure Person using the "typealias" keyword. After that, we created the object of structure using the Student alias and initialized and print the value of the structure.
need an explanation for this answer? contact us directly to get an explanation for this answer