zoukankan      html  css  js  c++  java
  • Structure of a C program: Preprocessor directives (#include <stdlib.h>, #define)

     Preprocessor programs provide preprocessors directives which tell the compiler to preprocess the source code before compiling.

    Examples of some preprocessor directives are: #include#define#ifndef etc.

    There are 4 main types of preprocessor directives:

    1. Macros
    2. File Inclusion
    3. Conditional Compilation
    4. Other directives

    Macros

    #include <stdio.h> 
    
    // macro definition 
    #define LIMIT 5 
    int main() 
    { 
        for (int i = 0; i < LIMIT; i++) { 
            printf("%d \n",i); 
        } 
    
        return 0; 
    } 

    File Inclusion

    1.Header File or Standard files: These files contains definition of pre-defined functions like printf(), scanf() etc.

    #include< file_name >

    2.user defined files: When a program becomes very large, it is good practice to divide it into smaller files and include whenever needed. These types of files are user defined files. These files can be included as:

    #include"filename"

    Conditional Compilation:

    Conditional Compilation directives are type of directives which helps to compile a specific portion of the program or to skip compilation of some specific part of the program based on some conditions. This can be done with the help of two preprocessing commands ‘ifdef‘ and ‘endif‘.

    #ifdef macro_name
        statement1;
        statement2;
        statement3;
        .
        .
        .
        statementN;
    #endif

    If the macro with name as ‘macroname‘ is defined then the block of statements will execute normally but if it is not defined, the compiler will simply skip this block of statements.

    Other directives

    #undef Directive: The #undef directive is used to undefine an existing macro. This directive works as:

    #undef LIMIT

    Using this statement will undefine the existing macro LIMIT. After this statement every “#ifdef LIMIT” statement will evaluate to false.

  • 相关阅读:
    用于json的 .ashx 小细节
    (转)写让别人能读懂的代码
    Mvc 中ViewBag Model 查找不到解决
    Windows 2008 R2 配置 DNS 实现二级域名
    Windows Server 2008 DNS服务器安装与配置
    【iOS】swift init构造器
    【iOS】OC-UTC日期字符串格式化
    android使用sharesdk的小感
    【iOS】Swift GCD-下
    【iOS】Swift GCD-上
  • 原文地址:https://www.cnblogs.com/JasperZhao/p/12897927.html
Copyright © 2011-2022 走看看