The source code to demonstrate the '\()' to embed the value of the variable within the string is given below. The given program is compiled and executed successfully.
// Swift program to demonstrate the '\()' to embed
// the value of variables within the string
var num:Int = 10;
var pi:Float = 3.14;
var str:String="Pi : \(pi)";
print("Num: \(num)");
print(str);
Output:
Num: 10
Pi : 3.14
...Program finished with exit code 0
Press ENTER to exit console.
Explanation:
In the above program, we created two variables num, pi initialized with 10, 3.14 respectively. Then we created a string variable str, which is embedded the value of variable pi within the string initialized in the str variable. After that, we printed the result on the console screen.
Program/Source Code:
The source code to demonstrate the '\()' to embed the value of the variable within the string is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created two variables num, pi initialized with 10, 3.14 respectively. Then we created a string variable str, which is embedded the value of variable pi within the string initialized in the str variable. After that, we printed the result on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer