Breaking

सोमवार, 13 अप्रैल 2020

BCA 2nd Sem Notes-C Preprocessor Definition

  • UNIT-I (Array)
Definition
Declaration & initialization of 1D 
Accessing array elements
Displaying array elements
Sorting arrays
Arrays and function
Declaration & initialization of 1D
Accessing and Displaying
Memory representation of array [Row Major, Column Major]
Multidimensional array

  • UNIT-II (Pointers)
  • Definition
    Declaration & initialization
    Indirection operator
    address of operator
    pointer arithmetic
    dynamic memory allocation
    arrays and pointers
    function and pointers

  • UNIT-III (Strings)

  • strlen(),strcpy(),strcat() ,strcmp()

  • UNIT-IV (Structures)
  • Definition

  • UNIT-V                                  (C Preprocessor)


  • UNIT-VI                                (File Handling)

  • Definition

    The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process.

    Preprocessor programs give preprocessors orders which advise the compiler to preprocess the source code before gathering. These preprocessor orders start with a '#' (hash) image. This ('#') image toward the start of an announcement in a C/C++ program demonstrates that it is a pre-processor order. We can put these preprocessor mandates anyplace in our program


    There are 4 main types of preprocessor directives:

    1. Macros
    2. File Inclusion
    3. Conditional Compilation
    4. Other directives
    1. Macros: Macros are a bit of code in a program that is given some name. At whatever point this name is experienced by the compiler replaces the name with the real bit of code. The '#define' mandate is utilized to characterize a full scale. Let us currently comprehend the large scale definition with the assistance of a program:

    #include <stdio.h>
      
    // macro definition
    #define HIGHT 5
    int main()
    {
        for (int i = 0; i < HIGHT; i++) {
            printf("%d \n",i);
        }
      
        return 0;
    Output:
    0
    1
    2
    3
    4
    In the above program, when the compiler executes the word HIGHT it replaces it with 5. The word 'HIGHT' in the large macro definition is known as a macro template and '5' is a macro expansion

    2. File InclusionThis kind of preprocessor order advises the compiler to remember a document for the source code program. There are two sorts of records which can be incorporated by the client in the program:
    1. Header File or Standard filesthese documents contain the meaning of pre-characterized capacities like printf(), scanf() and so forth. These records must be incorporated for working with these capacities. Diverse capacity is proclaimed in various header records. For instance standard, I/O functions are in 'iostream' document though works which perform string activities are in 'string' record Syntax:#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
              Syntax  #include"filename"

    3. 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‘.
    Syntax:
    #ifdef macro_name
        statement1;
        statement2;
        statement3;
        .
        .
        .
        statementN;
    #endif
    4. Other directives: Apart from the above directives there are two more directives which are not commonly used. These are:
    1. #undef Directive
    2. #pragma Directive: used #pragma startup and #pragma exit

    ---------------------------------------------------------------------------------------------------------------------------


    All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column. The following section lists down all the important preprocessor directives −

    Sr.No.Directive & Description
    1
    #define
    Substitutes a preprocessor macro.
    2
    #include
    Inserts a particular header from another file.
    3
    #undef
    Undefines a preprocessor macro.
    4
    #ifdef
    Returns true if this macro is defined.
    5
    #ifndef
    Returns true if this macro is not defined.
    6
    #if
    Tests if a compile time condition is true.
    7
    #else
    The alternative for #if.
    8
    #elif
    #else and #if in one statement.
    9
    #endif
    End preprocessor conditional.
    10
    #error
    Prints error message on stderr.
    11
    #pragma
    Issues special commands to the compiler, using a standardized method.



    कोई टिप्पणी नहीं:

    एक टिप्पणी भेजें