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.
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.
Output:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer