---
title: "c c++中 #define用法总结"
author: "sopestar"
date: "2009-03-26T16:17:13Z"
tags: ["C", "C#", "C++"]
slug: "c-c-define"
draft: false
lastmod: "2009-03-26T16:17:13Z"
id: 355636
url: "https://sopestar.iteye.com/blog/355636"
---

今天闲来无事 ，对 #define（宏）做一次总结。本质：替换功能，你define所有的东西在编译的时候会执行替换动作。

不论写c或者c++，对#define可能是最熟悉的了 ，下面列举其他用法：

1.简单的#define定义“全局变量”

2.define的“函数定义”

3。宏的单行定义

4。取消宏#undef

5。为了避免重复包含（重复定义）， 在一个.h文件开头会使用 #define ×××来定义。