ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

The #line directive Example in C | C preprocessor programs

The #line directive Example in C: Here, we will learn how #line preprocessor directive works in C programming language?
Submitted by IncludeHelp, on August 25, 2018

The #line is a preprocessor directive in C programming language; it is used to reset the line number in the code. We can reset line number from any line in the code.

Example:

#include <stdio.h>	/*line 1*/
/*line 2*/
int main(){	/*line 3*/
/*line 4*/
	printf("Hello world\n");	/*line 5*/
	//print current line	/*line 6*/
	printf("Line: %d\n",__LINE__);	/*line 7*/
	//reset the line number by 36	/*line 8*/
	#line 36	/*reseting*/
	//print current line	/*line 36*/
	printf("Line: %d\n",__LINE__);	/*line 37*/
	printf("Bye bye!!!\n");	/*line 39*/
/*line 40*/
	return 0;	/*line 41*/
}	/*line 42*/

Output

    Hello world
    Line: 7
    Line: 37
    Bye bye!!!

C Preprocessors Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.