Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Input/Output statements
  5. Pre-processor directives
  6. Line directive

Line directive

The line directive is used to reset the line number and the file name as reported by __LINE__ and __FILE__ macros. The line directive is used for the purpose of error diagnostics

It has two forms,

#line constant

The line directive of this form causes the compiler to ascertain that the line number of the next source line is equal to the decimal integer constant specified in the directive

#line constant “filename”

The line directive of this form causes the compiler to ascertain that the line number of the next source line is given by the decimal integer constant and the current file is named by the identifier filename specified in the directive

Example

#include<stdio.h>
int main()
{
	printf("Line no. is %d, File name is  %s \n",__LINE__, __FILE__);
	#line 200
	printf("Line no. is %d, File name is  %s \n",__LINE__, __FILE__);
	#line 100 "abc.c"
	printf("Line no. is %d, File name is  %s \n",__LINE__, __FILE__);
	return 0;
}

Output

Line no. is 4, File name is  line_.c
Line no. is 200, File name is  line_.c
Line no. is 100, File name is  abc.c

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments