×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

C #line Directive (Line Control Directive)

By IncludeHelp Last updated : March 10, 2024

What is #line Directive (Line Control Directive) in C?

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.

C #line directive Example

The below is an example of #line directive (or, line control directive) in C:

#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 »

Comments and Discussions!

Load comments ↻





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