All for Joomla All for Webmasters

C #define

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

Syntax:

  1. #define token value

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

  1. #include <stdio.h>
  2. #define PI 3.14
  3. main() {
  4.    printf(“%f”,PI);
  5. }

Output:

3.140000

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

  1. #include <stdio.h>
  2. #define MIN(a,b) ((a)<(b)?(a):(b))
  3. void main() {
  4.    printf(“Minimum between 10 and 20 is: %d\n”, MIN(10,20));
  5. }

Output:

Minimum between 10 and 20 is: 10
PinIt
submit to reddit

Leave a Reply

Top