Q:

Swift program to create an alias of basic types

0

Here, we will create an alias of basic types using the typealias keyword. Then we will create variables using created alias and print the value of created variables on the console screen.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to create an alias of basic types is given below. The given program is compiled and executed successfully.

// Swift program to create an alias of basic types

typealias MyIntType   = Int;
typealias MyFloatType = Float;

var num1:MyIntType   = 10;
var num2:MyFloatType = 20;

print("Num1: ",num1);
print("Num2: ",num2);

Output:

Num1:  10
Num2:  20.0

...Program finished with exit code 0
Press ENTER to exit console.

Explanation:

Here, we created two aliases MyIntTypeMyFloatType for integer and float type. Then we created two variables using created aliases and printed the value of variables on the console screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now