Q:

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

belongs to collection: Swift Basic Programs

0

Here, we will print the line number of source code using the #line directive 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 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 num1num2num3 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.

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

total answers (1)

Swift Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Swift program to print the size of variables... >>
<< Swift program to create an alias of basic types...