Breaking

मंगलवार, 14 अप्रैल 2020

BCA 2nd Sem Notes-Macro substitution directives

  • 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)

  • Macro substitution directives

    Macro substitution has a name and replacement text, defined with #define directive. The preprocessor simply replaces the name of macro with replacement text from the place where the macro is defined in the source code.
    Simple Macro Substitution Directive in c:
    syntax:
    #define identifier value
    Example:
    #define VALUE 10           //capital identifier name
    D=VALUE-5;
    Answer is 3


    A macro is a segment of code which is replaced by the value of macro. Macro is defined by #define directive. There are two types of macros:
    1. Object-like Macros
    2. Function-like Macros

    Object-like Macros

    The object-like macro is an identifier that is replaced by value. It is widely used to represent numeric constants. For example:
    #define PI 3.14
    Here, PI is the macro name which will be replaced by the value 3.14.

    Function-like Macros

    The function-like macro looks like function call. For example
    #define MIN(a,b) ((a)<(b)?(a):(b)) 

    C Predefined Macros

    ANSI C defines many predefined macros that can be used in c program.

    No.MacroDescription
    1_DATE_represents current date in "MMM DD YYYY" format.
    2_TIME_represents current time in "HH:MM:SS" format.
    3_FILE_represents current file name.
    4_LINE_represents current line number.
    5_STDC_It is defined as 1 when compiler complies with the ANSI standard.

    C predefined macros example

    File: simple.c
    1. #include<stdio.h>  
    2.  int main(){    
    3.    printf("File :%s\n", __FILE__ );    
    4.    printf("Date :%s\n", __DATE__ );    
    5.    printf("Time :%s\n", __TIME__ );    
    6.    printf("Line :%d\n", __LINE__ );    
    7.    printf("STDC :%d\n", __STDC__ );      
    8.    return 0;  
    9.  }    
    Output:
    File :simple.c
    Date :Dec 6 2015
    Time :12:28:46
    Line :6
    STDC :1

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

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