C #define

The #define preprocessor directive is used to define constant or micro substitution. It can use any basic data type.

Syntax:

snippet
#define token value

Let's see an example of #define to define a constant.

snippet
#include 
#define PI 3.14
main() {
   printf("%f",PI);
}

Output:

Output
3.140000

Let's see an example of #define to create a macro.

snippet
#include 
#define MIN(a,b) ((a)<(b)?(a):(b))
void main() {
   printf("Minimum between 10 and 20 is: %d\n", MIN(10,20));  
}

Output:

Output
Minimum between 10 and 20 is: 10
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +