Identifiers

Explain types of constants and identifiers


4 Answers
1-4 of  4
4 Answers
  • CONSTANTS-Constants are declared using 
    1)#define preprocessor:     #define n 10
    2) const keyword.
      Types:
    1)Integer constants:  int (eg:10,-90,0),unsigned int(eg:100u)
                                     long int ,long long int(112334567788)
    2)Floating point constants:  float and double(eg: 10.2and34889.89873)
    3)Octal or hexadecimal constants:octal(o13),hexa(ox13)
    4)Character constants:char enclosed with' '(eg: 'a')
    5)String constants: char enclosed with " "(eg:"Hello")
    6)Backslash constants:Escape sequences(\n,\t,\a,\v,....)

    IDENTIFIER:
    There are two types of identifier.
     1)Standard Identifiers
     2)User defined Identifier
    Example:
      int fact(int n)
    {
     int i,f=1;
    for(int i=1,i<=n;i++)
    f=f*i;
     return f;
    }
    int main()
    {
      int n;
       scanf("%d",&n);
       printf("The factorial is %d",fact(n));
       return 0;
    }
    In the above example 
      scanf is a STANDARD IDENTIFIER.
      n,i,fact(),f are all USER DEFINED IDENTIFIERS
      
     

  • Constants/Literals
    A constant is a value or an identifier whose value cannot be altered in a program. For example: 1, 2.5, "C programming is easy", etc.
    As mentioned, an identifier also can be defined as a constant.
    const double PI = 3.14
    Here, PI is a constant. Basically what it means is that, PI and 3.14 is same for this program.
    Below are the different types of constants you can use in C.
    1. Integer constants
    An integer constant is a numeric constant (associated with number) without any fractional or exponential part. There are three types of integer constants in C programming:
    decimal constant(base 10)
    octal constant(base 8)
    hexadecimal constant(base 16)
    For example:
    Decimal constants: 0, -9, 22 etc Octal constants: 021, 077, 033 etc Hexadecimal constants: 0x7f, 0x2a, 0x521 etc
    In C programming, octal constant starts with a 0 and hexadecimal constant starts with a 0x.
    2. Floating-point constants
    A floating point constant is a numeric constant that has either a fractional form or an exponent form. For example:
    -2.0 0.0000234 -0.22E-5
    Note: E-5 = 10-5
    3. Character constants
    A character constant is a constant which uses single quotation around characters. For example: 'a', 'l', 'm', 'F'
    4. Escape Sequences
    Sometimes, it is necessary to use characters which cannot be typed or has special meaning in C programming. For example: newline(enter), tab, question mark etc. In order to use these characters, escape sequence is used.
    For example: \n is used for newline. The backslash ( \ ) causes "escape" from the normal way the characters are interpreted by the compiler.
    Escape SequencesEscape SequencesCharacter\bBackspace
    \fForm feed
    \nNewline
    \rReturn
    \tHorizontal tab
    \vVertical tab
    \\Backslash
    \'Single quotation mark
    \"Double quotation mark
    \?Question mark
    \0Null character
    5. String constants
    String constants are the constants which are enclosed in a pair of double-quote marks. For example:
    "good" //string constant "" //null string constant " " //string constant of six white space "x" //string constant having single character. "Earth is round\n" //prints string with newline
    6. Enumeration constants
    Keyword enum is used to define enumeration types. For example:
    enum color {yellow, green, black, white};
    Here, color is a variable and yellow, green, black and white are the enumeration constants having value 0, 1, 2 and 3 respectively. For more information

    Identifiers:
     Identifier refers to name given to entities such as variables, functions, structures etc.Identifier must be unique

  • Identifiers are used as the general terminology for naming of variables, functions and arrays. These are user defined names consisting of arbitrarily long sequence of letters and digits with either a letter or the underscore(_) as a first character. Identifier names must differ in spelling and case from any keywords.
    There are certain rules that should be followed while naming c identifiers:
    1.They must begin with a letter or underscore(_).
    2.They must consist of only letters, digits, or underscore. No other special character is allowed.
    3.It should not be a keyword.
    4.It must not contain white space.
    Constants are also like normal variables. But, only difference is, their values can not be modified by the program once they are defined. Constants refer to fixed values. They are also called as literals.

C Plus Plus

Didn't get the answer.
Contact people of Talent-C Plus Plus directly by clicking here