您好,欢迎访问一九零五行业门户网

C语言中的预处理器命令是什么?

预处理器是一个在源代码通过编译器之前发送的程序。它根据以符号#开头的预处理指令进行操作。
类型预处理器命令有三种类型,如下所示:
宏替换指令。
文件包含指令。
编译器控制指令。
宏替换指令它将每个标识符的出现都替换为预定义的字符串。
定义宏替换指令的语法如下:
# define identifier string
例如,
#define pi 3.1415#define f(x) x *x#undef pi
示例以下是用于宏替换指令的c程序−
#define wait getch( )main ( ){ clrscr ( ); printf ("hello"); wait ;}
输出当上述程序被执行时,它产生以下结果 −
hello

文件包含指令可以使用#include指令来包含包含函数(或)宏定义的外部文件。
文件包含指令的语法如下:
# include <filename> (or) #include "filename"
示例以下是用于文件包含指令的c程序:
实时演示
#include <stdio.h>main ( ){ printf ("hello");}
输出当上述程序被执行时,它产生以下结果 −
hello

函数printf()的定义在<stdio.h>头文件中。
编译器控制指令c预处理器提供了一种称为条件编译的功能,可以用于在程序中打开(或关闭)特定的行(或一组行)。
示例以下是编译器控制指令的c程序:
实时演示
#if, #else, #endif etc.#define line 1#include<stdio.h>main ( ){ #ifdef line printf ("this is line number one"); #else printf("this is line number two"); #endif}
输出当上述程序被执行时,它产生以下结果 −
this line number one
以上就是c语言中的预处理器命令是什么?的详细内容。
其它类似信息

推荐信息