Getting started with C Language (2)

Introduction:

There are 2 nature of data: Constant and Variable

1)     Constants are the data that cannot be changed (example: PI is constant i.e. 3. 1418..)
2)     Variable is the nature of data that can be changed wherever required throughout the program.


In any program we do lot of calculations. the results of these calculations need to stored in computer memory to retrieve these values when required in program. for easy retrieval and usage of these values the names are given to the memory cells called as variable names.

Rules for constructing integer constants:

  1. Integer constant must contain one digit
  2. It must not have a decimal digit or value
  3. It can be positive or negative; if no sign mentioned default considered as positive.
  4. No commas and blanks are allowed in between the digits of number
  5. The integer range can be stored is -2147483648 to +2147483647 or -32768 to +32767(depends on compilers)
  6. Valid integer constants:
    1. 400
    2. -555
    3. 3089
    4. -4096
  7. Invalid integer constants:
    1. 50.36
    2. 0,88
    3. 0.74
Rules for constructing Real constants:

  1. They are also called as floating point constants.
  2. The real constant must have at least one digit
  3. It must have decimal point, if decimal point is not there it will be considered as whole.
  4. Default sign is positive
  5. No commas and blanks are allowed
  6. Valid examples:
    1. +655.6
    2. 888.6
    3. -63.36
    4. -7089
  7. Invalid examples:
    1. -42,6
    2. -12  .0

Rules for constructing character constants:

  1. A character constant is an alphabet, digit or a special character enclosed in a single inverted comma (‘ ‘)
  2. Character constants are also known as “One-byte integers”
  3. Valid examples:
    1. 'a'
    2. 'J'
    3. '8'
    4. '!'
  4. Invalid examples:
    1. "Z"
    2. 'ABCd'
    3. "C Language"

Primary Constants:

There are three type of variables as shown above i.e. integer, real(float), character; each type of variable can hold only the same type of value in it; integer variable can hold only integer value, real or float variable can hold only real values/floating values, character variables can hold only character constants in it.

Rules of constructing variable names:

  1. The variable name can be combination of 1 to 31 alphabets, digits and underscore (only in special character)
  2. It is a good practice to sum up the variable name length to 8/9caharcters only, as it saves writing efforts of writing much more long names and avoid errors in some big programs.
  3. The first character must be an alphabet or underscore ( _ ) only; no digit is allowed in starting of the variable name.
  4. No commas and space are allowed in variable name; it will generate error.
  5. No special symbol other than underscore ( _ ) is allowed in variable name.
  6. Valid variable names:
    1. speed_km
    2. C_lang1
    3. value1234_
    4. _abc
  7. Invalid variable name:
    1. 1_speed
    2. info@123
    3. C Lang

Keywords:

Keywords are the special names whose definitions are already written and explained to the c compiler

we cannot use keywords as variable names; nor we can modify keywords; they are reserved.

There are 32 keywords in C language as below:



Comments

Popular posts from this blog

Basic Structure of C Program