Sunday, January 13, 2019

variables and data types in C and operators in C

                        variables and data types in C


 a variable is an entity that has a value and is known to the program by a name. a variable define Associates a memory location with the variable name. a variable can have only one value assigned to eat at any given time during the execution of program . its value may change during the execution of the program.


here, A and B are variables.
  variable  names are identifier used to name variables. they are symbolic names given to memory location. A variable name consists sequence of a  of letters and digits, the first character being a letter. the rules that apply to identify also apply to variable names.

 example of valid variable name are:

a.                    abcl.                     stu-data
class.             employee.             12MAX
 examples of invalid variables  names are:
a's- illegal character(')
Stu data- blank space are not allowed
2MAX- first character should be a letter
Class,mark- comma not allowed

 basic data type :

 the C language support the following basic data types:
char                                         -                                    a single bird that can hold one character
  int                                          -                                   an integer (non-decimal number) (2 bytes space)
float                                         -                                  a number with decimal value ( 4 bytes)
double                                      -                                  number with decimal value (8 bytes)


  a qualifiers  alters the characteristics of the data types, such as its size or sign. in c u can apply qualifiers to above data type to get additional data types. the qualifiers that alter the size are 'short' and 'long'.
 short int                           -                           integer represented by a laser number of bits (usually 16)
 long int                            -                       integer represented by a greater number of bits (usually 32)
 long double                      -                          an extended decimal number.
 the expect size of these data types depends on the compiler.

the sign qualifiers are "signed" and "unsigned"

  1. signed int
  2.  signed long int
  3.  unsigned short int
  4. unsigned int
  5. unsigned long int
  6. signed char
  7. unsigned char
normally qualified (short and long) cannot be applied to the data types 4 and plot and sign qualified (signed and unsigned) cannot be applied to float, double and long double.

 operators in C

 operator are symbols that act upon data. they represent a particular operation to do performed on the data. operators can be kal classified  in the following categories:

* arithmetic operators:

The arithmetic operator performs arithmetic operation on any built in data types.
  •  operator.                function
  •  +                            addition
  •  -                              subtraction
  • ×                             multiplication
  • /                              exponentiation
  • %                            modulus (remainder)

* special arithmetic operators

  • ++  increment
  •  - -    decrement

X++ OR ++X is equivalent to X=X+1
X-- OR --X is equivalent to X=X-1
 relational operators these operators are used to compare two values on the basis of a certain condition.


  • <           less than
  • <=         less than equal
  • >            greater than
  • >=          greater than equal
  • !=            not equal to
  • ==            equal to

 logic operators:

 these operators are used to perform logical operations.
 operator      function

  • &&         and
  • ||              OR
  • !              NOT

 assigning operators:

 this operator are used to assign value to variables.
 operator     function

  • =        assign a value
  • +=      add the value and assign it to the left
  • -=       subtract the value and assign it to the left
  • *=       multiply the value and assign it to the left
  • /=        divide the value and assign it to the left
  • %=      find the remainder and assign it to the left

  ternary operators:

 these operators are very powerful operator in C. in some cases it is equivalent to the "if"- else statement.

operation("?") and(":")
 Syntax= expression=exp1?exp2:exp3;
b=a>100?25:35 ;
 hear the value of will be 35 because is less than 100 and condition is false.