Page 159 - DCAP507_SYSTEM_SOFTWARE
P. 159

Unit 10: Programming Languages Concept (I)




          X,Y, Z : VALUE;                                                                       Notes
          W: LETTER;
          Thus defined variables RESULT  and answer can have values from 1 to 100, similarly X,Y, Z, can
          have from 2 to 15 and W can have from the list : 'A', 'B', 'C', … 'Z'.

          The typedef Statement

          In addition to creating new data types, C allows both standard and user-defined data types to be
          renamed using typedef statement. The syntax is:
          Typedef data - type   data - identifier
                         New name

                         Predefined data-type
                         Reserved word


                 Example:
          Typedef float REAL;
          Makes the  name REAL a synonym for float. The name REAL can now be used in place of the term
          float. For example, the declaration
          REAL  val;
          The typedef does not create a new data type; it creates a new name for an existing data type.
          The #define statement is used to create synonym for an existing data type Similarly # define
          preprocessor command is used to equate constants and operators to create symbolic names.


                 Example:
          #define PI 3,1416 -  equate symbolic name PI to the number 3.1416.
          #define TIMES * -  equates symbolic name TIMES to the operator *. The  substitutions  are
          made by the C preprocessor just prior to program compilation.  The symbolic name is referred
          to as a macro.

          10.3.3 Structure Data Types

          Structure data types are formed from primitive data types. Arrays, Records, Files are examples
          in PASCAL and Arrays, Structures, Unions, Files in C language. Records, Structures & Unions,
          etc., are discussed in the following section.

          The RECORD and STRUCTURE

          A collection of related data items (or fields), treated as a unit, is called a record. Whereas a set of
          related records is referred to as a file.  To understand this concept, suppose a file of students at a
          NDIMCRC centre having data items registration no. (reg.no.), name , course & telephone.

          Since array can have data-items only of identical type, the above information can be stored in
          record type structure.  So in record type structure, one can store related the data-items which are
          distinct in nature and type.





                                           LOVELY PROFESSIONAL UNIVERSITY                                   153
   154   155   156   157   158   159   160   161   162   163   164