Wednesday 31 July 2013

Q: What is Operator ?


Operator:
                
Operator is a system defined symbol which works on some values or expressions and return another value .
  ex-  3+4 is equal to seven,here 3 and 4 are operand
and '+' is operator.
'C' language has rich library of operator category.
Some operators are:-

  1. Assignment Operator
  2. Arithmethic Operator
  3. Relational Operator
  4. Logical Operator
  5. Increment Operator
  6. Decrement Operator
  7. Bitwise Operator
  8. Size of() Operator 
 
1. Assignment Operator (=) :  It is used to assign the value of expression of right hand side to a storage space on left hand side.
'C' language support short hand assignment operator.


Operator

 Expression
 Assignment Operator
+ =

X= X+Y
  X += Y
- =
X= X-Y 
X -= Y

 * =
X= X*Y
X *= Y

 / =
X= X/Y
X /= Y 

 % =

X=X%Y
X %= Y  
2. Arithmetic Operator :- Arithmetic operator returns a value after working on some expression.These operator works on two operand
Operator          

+

-

*

/

%
Operation

Addition

Subtraction

Multipication

Division

Remainder
3.Relational Operator :  Relational operator compares two value of an expression and return true or false dependind upon the comparison.
some relational operator are:    <,<=, >, >=, == , !=

Logical Operators

Logical operators are used to combine expressions containing relation operators. In C, there are 3 logical operators:
- See more at: http://www.programiz.com/c-programming/c-operators#logical

Logical Operators

Logical operators are used to combine expressions containing relation operators. In C, there are 3 logical operators:
- See more at: http://www.programiz.com/c-programming/c-operators#logical
4.Logical Operator :- 
                       There are 3 logical operators:
||  logical OR
&&  logical AND
!  logical Not

a. Logical OR operator(||) :-    This operator also known as short-circuit logical OR operator. This operator check two conditions. It worrks ,if one or all two condition true than result true , otherwise result false.
Operand 1

 Operand 2

 Operand 1 || Operand 2

 False
False

False

False
True
True

 True

 False
 True
 True
 True

 True
b. Logical AND Operator(&&) :-  This operator also known as short-circuit logical && operator.This operator check two conditions. It works, if all conditions true than result true , otherwise result false.
Operand 1
 Operand 2
 Operand 1 && operand 2
True
  True
 True
True
  False
  False
False
True
  False
 False
 False
 False
c.Logical NOT Operator (!) :-    It is a unary Operator .
Operand 1
 Operand 2
False
 True
 True
 False
5.Increment Operator (++) :-    Increment Operator increase the value  of the variable by one .

Expression        Operator
X=X+1                 X++
X=1+X                 ++X
6. Decrement Operator (--) :-  Decrement Operator decrease the value of the variable by one

Expression        Operator
X=X-1                 X--
X=1-X                 --X
7.Bitwise Operator :-  Bitwise operator is used to manipulate data at binary level.
                                                    They are used to certain operation faster .
                                                    All bitwise operator works only on integers or character type data.

   'C' Support following bitwise operator.
a. Bitwise Logical Operator :- 
Operator              Meaning
   &                      Bitwise  AND     
   |                        Bitwise  OR
   ^                        Bitwise  XOR
b. Bitwise Shift Operator :- 

Operator               Meaning
  >>                        Right Shift
  <<                        Left Shift
c. Bitwise One's Complement Operator :-
Operator               Meaning
    
                  one's complement
8. Sizeof()  Operator:-     The sizeof operator returns the size of its operand in bytes. The sizeof operator always precedes its operand. The operand may be an expression or it may be a cast.
Example:

            Suppose i is an integer variable and c is a character type variable then

Printf(“Size of integer : %d”,sizeof(i));
Printf(“Size of character : %c”,sizeof(c));
Might generate the following output :
Size of integer : 2
Size of character : 1
Click to edit your
Website Header.
Drag to Move

Tuesday 30 July 2013

Data Types in C language



Data Types

The nature of variable is referred as data type.The data type determines the kind of data which is going to be stored in the variable declared of that type.  It plays important role to declare variables. It prevents invalid data entry in the program. The biggest advantage of data type is efficient use of memory space.
Data type can be classified into following sub-heads.
1.Basic Data Types
2.User Defined Data Types
3.Derived Data Types

1.Basic data types :
Data Type
 Descriptions
 Keyword
  Memory
 Conversion
 String
         Range
(on 16 bit machine)
 Integer
 Whole number
 int
 2 bytes
 %d
 -32768 to +32767
 Character
 Single characte
 char
 1 bytes
 %c
 -128 to +127
 Floating
Point
 Real number
(precision:- 06 places)
 float
 4 bytes
 %f
 3.4e-38 to + 3.4e+38
 Double-Precision
floating point
 Real number
(precision:- 12 places)
 double
 8 bytes
 %lf
 1.7e-308 to 1.7e+308
2.User defined Data Types:

         User defined data types are those data types that define by the users.
 a.Type Defination:-
                                   Type definition is used to provide an alternate name to existing data type.

Type definition does not create a new data type; it just assign a new name.

The keyword “typedef”  is used to fulfil the purpose  means using keyword “typedef” user can change name of data type.

 Ex- if user want change name of data type ‘int’ to ‘number’ than use the “typedef” keyword.

The Syntax is:

     typedef  ‘data type’  ‘new name’ ;
ex-
   #include<stdio.h>

   typedef int number

   void main()

  {

     number   x=1;

      printf(“X=%d”,x);

  }
  output:- 1


b.Enumerator:  

Enumerator data type is defined to store specific set of constant.

Enumerator data type essentially defines a set of constants of the type int.

The variables of enumerated data type can store only one value from

Specific set only. The Keyword “enum” is used to create  enumerated data type

The syntax is

         enum “enum_tag” {enumeration constants};

         enum enum_tag  variables;

   Enumerated data type makes programs more readable(advantage).

The enumerated values cannot be used directly in I/O functions(Disadvantages)

# include<stdio.h>
enum division  {Fail,First,Second,Third} ;   /* 'enum division' is a user defined data type */
void main()
{
  enum division status;            /*'status' is a variable of data type 'enum division' */
  status=First;                        /* value of 'status' is first*/
if(status==First)
  printf("Congratulation");
else
     printf("Put Efforts");
}

3. Derived Data Type:

Derived data types are devised from existing data types. “C” language supports various derived data type like array, structure, union, pointer etc.

Array is the collection of homogeneous data while structure and union are the collection of heterogeneous data .pointer stores the address of some other variables.  

Drag above, below or to the sides of any module.
Click to edit your
Website Header.
Drag to Move

What are Tokens in c language?

Tokens:-
                  Tokens are the smallest individual unit of any language . It is the smallest element in the 'C' language .

Tokens are :-
  1. Constant
  2. Keyword
  3. Identifiers
  4. Punctuation
  5. Operators
1. Constant :- A constant value is the one which does not change during the execution of a program
  Types of constant:-
  1.  Integer Constant
  2. Real Constant
  3. Character Constant
  4. String constant

2. Keyword :- The word which have special meaning to the compiler is called keyword. The meaning of keyword can't be changed. They are also called reserved word . Keyword can't be used as a variable name . They are 32 keywords in 'C' . All keyword are in lower case .
List of keywords

  1. auto                           
  2. break 
  3. case
  4. char
  5. const
  6. continue
  7. default
  8. do
  9. double
  10. else
  11. enum
  12. extern
  13. float
  14. for
  15. goto
  16. if
  17. int
  18. long
  19. register
  20. return
  21. short
  22. signed
  23. size of
  24. static
  25. struct
  26. switch
  27. typed ef
  28. union
  29. unsigned
  30. void 
  31. volatile
  32. while
3.Identifiers/ Names
Identifiers is the name of user-defined variable, array and functions .
'C' is a case-sensitive language that is upper case and lower case alphabets are different for 'C'.
  Ex- 'Num' and 'num' are two different identifiers for c language.
Rules of identifiers :-
  • First character must be an alphabet or underscore.
  • Identifiers name must consist of only letters, digits and underscore.
  • An Identifier should have less than 31 characters.
  • The keyword can not be used as identifiers.
  • No comma or blank are allowed with in an identifier.

4.Punctuations:-
Semicolons,colons,commas,apostrophes,quotations mark,braces,brackets and parentheses .
 ; : , ' " () {} [] * = # .

5. Operators :-
  • Assignment Operator
  • Arithmetic Operator
  • Relational Operator
  • Logical Operator
  • Increment Operator
  • Decrement Operator
  • Boolean Operator
  • Bit-wise Operator
  • Size of() Operator
  • Comma Operator


Q: What is 'C' language

'C' language is widely used in computer technology. C language is inspiration for development of other languages .

History:

  • Developed by Dennis Ritchie at AT & T lab in 1972 . 
  • American National Standard Institute approved a version of ‘C’ in 1989 ANSI-C
Features:
  • ‘C’ is compiler based language.
  • ‘C’ is a case sensitive language because its lower and upper case letters are different .
  • It ignores white space character.
     Ex- Space, Tab, Carriage return, from feed, Newline.

Character Set:

character set of a language refers to the group of keys that are used to create words of expression of that language. Character of 'C' language is classified into 4 categories.

  • Alphabet :-  26 Upper case and 26 Lower case alphabet   i.e.  A-Z and a-z
  • Digits:-         0,1,2,3,4,5,6,7,8,9
  • Special characters:- ! @ # $ % ^ & * () {} [] . ,  ; ;  “  ‘  > < / ?
  • White spaces:- Space, Tab, Carriage return, from feed, Newline .
     note-The compiler ignore white spaces characters .