Elements of C

                                Every language has some basic elements and grammatical rules. These basic elements are character set, variables, datatypes, constants, keywords, variable declaration, expressions, statements etc,. all of these are used to construct a c program.

2.1 Character set:

Upper and lower case
                        A,B,C,D,……..Z
                        A,b,c,d,………z
Digits
                        1,2,3,4,….
Graphic Characters


White space characters
                        Space character, neline character, horizontal tab, vertical tab, and form feed.
Other characters
                        Alert, backspace, carriage return, and null character.

2.2 Escape sequence/ Execution characters:

                       C supports combination of backslash ( \ ) and some characters from the C character for representing these characters in our C programs. These characters are known as escape sequences.


2.3 Delimiters

These are used for syntactic purpose in C

               :           colon                     used for label
               ;           semicolon             end of statement
               ()          parentheses          used in expression
               []          square brackets    used for arrays
               {}          curley braces       used for block of statements
                #          hash                     preprocessor directive
                ,           comma                 variable delimiter

2.4 Keywords:

                       Keywords are the vocabulary of C. Because they are special to C, you can't use them as identifiers, for example, or as variable names. Many of these keywords specify various types, such as int. Others, such as if, are used to control the order in which program statements are executed. These are always written in lowercase. There are only 32 keywords available

auto       break    case      char        const       continue   default           do         double         else
enum     extern    float       for          goto         if             int                  long      register        return    
short     signed    sizeof     static       struct       switch      typedef          union    unsigned      void      volatile        while

2.5 Identifiers :

                        All the words that we will use in our c program will be either keywords or identifiers. Keywords are predefined and can’t be changed by the user, while identifiers are user defined words and are used to give names to entities like variables, arrays, functions, structures etc., Rules for naming identifiers are

Rule 1: the name should consist of UPPERCASE, lowercase, digits and underscore(_).
Rule 2: First character should be alphabet or underscore.
Rule 3: The name should not be a keyword.
Rule 4: C is a case sensitive, the lowercase and uppercase letters are different.
Rule 5: Some implementations of C recognize only the first eight characters, though most implementations recognize 31 characters.

Examples of valid Identifiers are :

Temp                a          _initial               data_type         Marks               Percent

Invalid identifiers are:

5abd                 int         rec#      avg.no              high num(space not allowed)

Keep in mind all these rules before using identifier.

Share this

Related Posts

Latest
Previous
Next Post »