Thursday, 12 July 2012

Importance Of C


                                                                 C
C is a robust language. means rich set of built in functions and operators  can be used to write any complex program.
Programs written in C are efficent and fast.
There are 32 keywords and several standard functions are available which can be used for developing program.
c is highly portable. this means that c programs written for one computer can be run on another with litte or no modification.
c programing language is structred programming language. means  data can be written in module or function or blocks.
a proper collection of these modules make a complete program.
A simple Program
----------------------------

#include<stdio.h>
main()
{
/* printing begin */
printf(""This is my first program");

}  /* this is main block closed */


Execution of C program
1) Createing the program
2) compiling the program
3) Linking the program with functions that are needed from the  C Library
4) Executing the Program.
Ms Dos operating system would load program stored inthe file .c  generate the Object Code  this code stored in another file name is
.obj
which generate the executeable code with file name is  .exe


C Tokens

 text data, individualwords and puncuation marks are called tokens

c tokens are
 keywords
Constants
Strings
Operators

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


Integer Constants
----------------------------
A integer constant refers to a sequence of digits. There 3 types
Decimal, octal and hexadecimal.
Decimal consists 0.......9 preceded by an + or – sign.
Hidden spaces, commas,and non-digit charagacter s are not permitted between digits.
23 567
20,000
$34909
An octal number consists of any combination of digits from the set 0 through 7 with a leading 0.
A sequence of digits preceded by 0x and 0X theymay also include alphabets A through F for a through f.ex:
0X2
0x9F
Real constants
Integer numbers are inadequate to represent quantities that vary coninuously. Such as distance , heights ,price etc...
0.003like
A real number may be expressed in decimal notation or an integer.

Like
0.65e4;

Single character constants


String constants

Backslash character constants
------------
‘\a’     bell.
‘\b’      backspace
‘\f’       form feed
‘\n’      new line
‘\t’      Harizantal tab;
‘\v’        vertical tab;
‘\”        single quote
‘\” ‘               double quote
Data types
--------------
Primary data types
Intger
Singen type     unsigned type
Int           unsigned int
Short int            unsigned short int
Long int                   unsinged long int
Float
Float
Double
Long double

Ranges
Char                -128  to 127
Int                                  -32,768 to 32,767
Float             3,4e-38 to 3.4e+38
Double            1.7e-308 to 1.7e+308


Size and Range of Data Types(bits)
Char                     8      -128 to 127
Int                        16      0 to 255
Short Int      8       -128 to 127
Long         32       -2,147,483,648 to 2,147,483,647
Float         32       3.4E-38 to 3.4e+38
Double        64       3.4E-4932 to 1.1E+4932

How we Declare a Variable
After design a suitable variable names
1). It tells the compiler what the variable name
2) It specifies what type of data the variable will hold.
Data – type v1,v2,v3;


Int  count;
Double ratio;

Typedef
C supports a feature as type definition that allows users to define an identifier that would represent an existing data type.
 Typedef      type      identifier
Typedef  int  units;
Main()
{
Float x;
Double y;
Long int n;
Printf(“%f”,x);
Printf(“%lf”,y);
Printf(“%ld,n);
}

Declaring a variable as constant
The value of certain variables to remain constant during the execution of a program.
Const int size=30;
Printf syntax;
Scanf syntax;


  CHAPTER 2
C  supports  set of operators. Like are =,+ -  * & and < >
1)   Arithmetic operatos
2)   Relational operators.
3)   Logical operators.
4)   Assignment operators.
5)   Increment and decrement operator
6)   Conditional operator
7)   Bitwise operators
8)   Special operators.

ARITHMETIC OPERATORS
 C language provide  basic operators are  +, -, /, %, *
+                 -----------     Addition
-               ------  subtraction
*      ----   multiplication
/     ------   division
%   ------ modulo division

Modulo division operator % cannot be used on floating point data.
Ex:   a+b;
Here a,b are operands.
Integer arithmetic always get an integer value.
If a=14 , b=4 then
a-b=10;
a+b=18;
a*b=56;
a/b=3
a%b=2(remainder)
if you give like this
6/7=0;
If u give like
-6/-7=0;
RELATIONAL OPERATORS
 These operator used for compare two depending on their relation. Take certain decisions.
The operators are
Operator
  Meaning
< 
less then
<=
Less then or equal
> 
greaterthen
>=
Greaterthen or equal
==
Equal to
!=
Not equal to

Logical operators
&&         ----   logical AND
||          ----  logical OR
!             ---   logical NOT
The logical && and || are used for test more than one condition and make ecisions.
a>b  &&x==10

ASSIGNMENT OPERATORS
 To assign the result of an expression to a variable.
Assign operator =
Ex;
X=x+20;
We can write like this
X+=20;
INCREMENT AND DECREMENT OPERATOR
 The increment and decrement are 4 types
Pre increment     ++p;
Post increment      p++;
Pre decrement      --p;
Post decrement       p--;
These operator used for while looping to automatically increment are decrement a value.
CONDITIONAL OPERATOR
 A ternary operator used for to test a single condition
Exp1 ? Exp2 : exp3;
X=(a>b)?a:b;
BIT WISE OPERATORS
 This is used for manipulation of data at bit level these operator  used for testing the bits,
Shift bit s left to right or right to left
Bitwise opertors are not used on float or double.
& ,| , ^ ,<<, >>,~

No comments:

Post a Comment

Write your openion about my blog spot..To get automatic facebook updates like my Pagehttps://www.facebook.com/shivashankar4u ..It takes only 1 min to write the comment and to like the page.. Thanks.