C Programming Language Tutorial
Variables and Data Types
Input/Output
Looping and Selection Structures
Array
Functions
Preprocessing Command
Pointer
Structure
File Operations
Important Knowledge
In summary, the C programming language provides several preprocessing commands that are used to modify the source code before it is compiled. These commands include:
#include
: This command is used to include the contents of another file in the source code.
#define
: This command is used to define macros, which are text substitutions that the preprocessor performs on the source code.
#ifdef
and #ifndef
: These commands are used for conditional compilation, which allows you to include or exclude sections of code based on compile-time conditions.
#if
and #else
: These commands are used for more complex conditional compilation.
#pragma
: This command is used to provide additional information to the compiler.
Preprocessing commands are included in the source code using a #
symbol at the beginning of the line, followed by the command and any necessary parameters. Preprocessing commands can be used to improve code readability, define constants and macros, and perform conditional compilation based on compile-time conditions.
It's important to note that preprocessing commands are processed before the source code is compiled, so they can significantly affect the behavior of the program. Therefore, it's important to use preprocessing commands carefully and only when necessary.
Overview of C preprocessor directives:
#
symbol.#include <stdio.h> #define PI 3.14 int main() { printf("Value of PI: %f\n", PI); return 0; }
List of common C preprocessing commands:
#define
for defining macros, #include
for including header files, #ifdef
for conditional compilation, and others.#define MAX_VALUE 100 #include <stdio.h> #ifdef DEBUG #define DEBUG_PRINT(msg) printf("Debug: %s\n", msg) #else #define DEBUG_PRINT(msg) #endif int main() { int array[MAX_VALUE]; DEBUG_PRINT("Debug message"); return 0; }
C preprocessor cheat sheet:
// C Preprocessor Cheat Sheet #define MACRO_NAME value // Define a macro #include <header.h> // Include a header file #ifdef CONDITION // If condition is defined #ifndef CONDITION // If condition is not defined #else // Else part of #ifdef #endif // End of #ifdef block
#define MAX_VALUE 100 #include <stdio.h> #ifdef DEBUG #define DEBUG_PRINT(msg) printf("Debug: %s\n", msg) #else #define DEBUG_PRINT(msg) #endif int main() { int array[MAX_VALUE]; DEBUG_PRINT("Debug message"); return 0; }
C programming preprocessor commands summary sheet:
#ifndef
, #undef
, and others.// C Preprocessor Commands Summary Sheet #define PI 3.14 // Define a constant #include <stdio.h> // Include a standard header file #ifndef MAX_SIZE // If MAX_SIZE is not defined #define MAX_SIZE 100 // Define MAX_SIZE #endif // End of #ifndef block #undef PI // Undefine a previously defined macro