Biyernes, Marso 15, 2013

2.2 Types of Data




2.2
            Types of Data
           
            A C program is composed of a sequence of characters that are grouped by a compiler into identifiable tokens. These tokens can be classified as literals, identifiers, and keywords.
             
             
             
             
           
              
              
              
              
              
              
              
              
              
              
              11
             Chapter 2
            2.2.1 Literals
           
            Literals are classified under numeric and non-numeric literals.
           
           
            2.2.1.1 Numeric Literals
           
            Numeric literals can be further subdivided into whole numbers and real numbers.
            Whole numbers are also called integers. These types of numbers do not contain any fractional part and it should not have a decimal point. Real numbers, on the other hand, are also called floating point numbers. These numbers have fractional parts and it could also be expressed using scientific notation.
           
           
            Exponential representation may be used to represent real numbers. An exponential representation consists of an integer or real value followed by e then an integer value in the exponential base 10.
           
             Example.  
            2.5e2 is the same as 2.5 x 102, which is equivalent to 250.0
              
              
            2e4 is the same as 2 x 104, which is equivalent to 20000.0
           
           
            2e0 is the same as 2 x 100, which is equivalent to 2.0
           
           
            2.e5 is the same as 2.0 x 105, which is equivalent to 200000.0
           
           
            In defining numeric literals, the following rules should be followed: 1. No
            comma.
            2. No space between the unary sign (+ or -) and the digits.
            3. Must begin and end with a digit.
           
           
            2.2.1.2 Non-Numeric Literals
           
            Non-numeric literals may be in the form of a character or a series of characters. A series of characters is called a string. A string should be enclosed in double quotes, while a character is enclosed in single quotes. Some special characters may be used, but it should be preceded by the escape character (backslash).
           
             Example.
            ‘a’
              
              
            ‘I’
            ‘+’
            ‘2’
              
              
            “De La Salle University”
           
           
            “a string with double quotes \u8221? within”
           
           
            “a single backslash \ is in this string”
           
           
           
           
           
           
             12
             Overview to C Language
           
            Other escape characters are listed below.
           
            Escape Character
            Meaning
            alert
            tab
             null
            character
            \u8217?
            single quote
             percent
            symbol
           
           
            2.2.2 Identifiers
           
            Identifiers are composed of a sequence of letters, digits, and the special character _
            (underscore). Identifiers are defined by the programmer, thus they should be descriptive. Avoid using names that are too short or too long. Limit the identifiers from 8 to 15 characters only.
           
           
            Some rules must be followed for defining identifiers. They are as follows: 1. It must consist only of letters, digits, and underscores.
           
             Correct Example
             Incorrect Example
            _duh x-1
            thisisanidentifier2 num#
            a large
            num
            num_1 y?
           
            2. An identifier cannot begin with a digit.
           
             Incorrect Identifier
            1name
            3to4
           
            3. An identifier defined in the C standard library should not be redefined.
           
             Incorrect Identifier
            printf
            scanf
           
            4. Identifiers are case sensitive; meaning uppercase is not equal to the lowercase.
              
             Example.  ans
            ≠ Ans ≠ aNs ≠ anS ≠ ANs ≠ ANS
           
           
           
           
              
              
              
              
              
              
              
              
              
              
              13
             Chapter 2
            2.2.2.1 Variables
             
            Variables are identifiers that can store a value that can be changed. These can be of different data types. They can store literals or some type of structured data.
            Structured data can contain one or more values or data.
           
           
            2.2.2.2 Constants
             
            Constants are identifiers that can store a value that cannot be changed. Usually, constant identifiers are all capital letters with underscores between each word to distinguish them from variables.
           
           
            2.2.3 Keywords
           
            Keywords are words that have a strict meaning in C. These are special words
            “reserved” by the programming language for processing, thus these may not be redefined by the programmer. Some keywords are listed below.
           
            auto double
            int struct
            break else long switch
            case enum
            register
            typedef
            char extern
            return
            union
            const float short unsigned
            continue for
            signed void
            default goto
            sizeof volatile
            do if static
            while
             
             

Walang komento:

Mag-post ng isang Komento