Swift program to print the line number of source code using the #line directive

Here, we are going to learn how to print the line number of source code using the #line directive in Swift programming language?
Submitted by Nidhi, on May 30, 2021

Problem Solution:

Here, we will print the line number of source code using the #line directive on the console screen.

Program/Source Code:

The source code to print the line number of the source code using the #line directive is given below. The given program is compiled and executed successfully.

// Swift program to print the line number 
// using "#line" directive

var num1 = 10;
var num2 = 20;
var num3 = 0;

print("Line number: ",#line);

num3=num1+num2;

print(#line,"Result: ",num3);

Output:

Line number:  8
12 Result:  30

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

Explanation:

In the above program, we created three variables num1, num2, num3 using var keyword, that are initialized with 10, 20,0 respectively. Then calculate the sum of both variables and print the result on the console screen.

And, we printed the source code line number using the "#line" directive on the console screen.

Swift Basic Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.