Saturday, August 27, 2011

Control flow statements in C

Control flow statements are used to check condition in program and to decide whether they should be executed or not.Following are control flow statements:
1.IF Statement: This statement is used to check condition of expression whether it is true or not,if true then it executes the expression,and if it is false then it simply ignores it.
2.IF....Else :  This statement is similar to if,only when first condition is false,it jumps to expression under Else statement and execute it.
3.While : This is used to execute a block of code repeatedly,until condition becomes zero.
4.do...While: This is used to execute code at least once,before condition is checked.
5.for Statement: This is used to execute code for certain number of times where a variable is initialized and set as counter outside the loop.
6. Switch Statement: This is used to deal with more than one cases on which different statements are executed.
7.Break and Continue: Break statement is used to break any loop such as while,do while and for and continue statement is used to continue loop.

Thursday, August 25, 2011

Input/Output Operations

Input/Output operations are the operation used to take input from user and to display output on monitor by program.This whole process can be referred as Input/Output Management.Mainly stdlib is the standard library file for input/output operations.For accepting input from user standard input i.e stdin data stream is used and for output it is stdout.Hence as we learn from previous post for input/output functionality in program ,stdio.h has to be include.
Mainly to print output we use printf function and to accept input we use scanf function.

Syntax of  both functions are as follow;
#include<stdio.h>
void main()
(
 int a;
printf(" Enter an integer number");
scanf("%d",& a);
printf("Your entered integer is %d",a);
}

as we see % d is use to accept decimal integer number ,like this there are more controls to accept different value i.e
  • %c           - a single character
  • %i            - an integer
  • %s           -a string
  • %e,%f,%g - used for floating point
  • %o            - an octal number
  • %x           -a hexadecimal number
  • %p           - a pointer
  • %u           - an unsigned integer
  • %lf           - as double floating pt
  • %Lf          - as long double floating pt

Tuesday, August 23, 2011

Operators,Operands & Expression in C

In C language ,to perform any arithmetic or logical computation we used operators.Operators are nothing but the symbols which uses operands or expression to perform these computation.Following are types of Operators available in C:-
1.Arithmetic Operators:
  •     +      to perform Addition
  •     -       to perform Subtraction
  •           to perform Multiplication
  •     /        to perform Division
  •     %      mod for finding remainder in division
  •     ++     for increment
  •     --       for decrement
 
2.Assignment Operators:
  •                  simple assignment
  •    +=             addition assignment 
  •    -=              subtraction assignment
  •    *=              multiplication assignment
  •    /=               division assignment
  •   %=             mod assignment
  •   <<=            left shift assignment
  •   >>=            right shift assignment
  •   &=             bitwise AND assignment
  •   ^=              bitwise exclusive OR assignment
  •   |=               bitwise inclusive  OR assignment 
3.Logical/Relational Operators:
  •   ==         equal to
  •   !=          not equal to
  •   >           greater than
  •   <           less than
  •  >=          greater than or equal to
  •  <=          less than or equal to
  •  &&        logical AND if both operands are non zero condition becomes true
  •   ||            logical OR if either one operand is non zero condition becomes true
  •   !            logical NOT ,use to reverse the logical state of operands if condition is true it will make it false
 
4.Bitwise Operator:
  •    &         binary AND operator
  •     |          binary OR operator
  •     ^         binary XOR operator
  •     ~         Ones Compliment
  •     >>       binary right shift operator
  •     <<       binary left shift operator 
Now something about Expression, it is nothing but combination of operands and operators.i.e
            a=b+c; it is called expression
            where a,b & c are operands, +  and = is operator. 

Monday, August 22, 2011

Data Types in C

So now we are going to see what exactly Data Types are in C language.Usually Data Types are used to store various types of values which is going to be processed by program.Data types determines allocation of memory for the data or values which are to be processed by program.Following is the list of data types in C:-
1.Integer:- This data type is used to define integer number.
           {
                int a;
                a=2;
           }
2.Float:- This data type is used to define floating point numbers.
           {
              float b;
              b=10.3;
           }
3.Double:-This data type is used to define big floating points number.
           {
             double c;
             c=12000;
           }
4.Character:- This data type is used to define characters and its size is only one byte.
           {
               char option;
               option=d;
           }
 All above are basic data types in C. Further all these data types have different options such as
short int=2 bytes ; unsigned short int=2 bytes ; unsigned int=4 bytes ; long int=4 bytes;

signed char=1byte; unsigned char=1 byte;

long double=8 bytes;

Saturday, August 20, 2011

Syntax of C program !

In the previous post we have seen introduction of C and its advantage,now we will see how to write a simple C program or know how is simple syntax of C program.First of all we must know that a program consist of one or more functions,functions are nothing other than group of statements which are executed together so that program can perform specified task.The main( ) function is one of the important function in C programming , as execution of each and every C program starts with main( ) function.So now we will see a simple and most famous example of C program from which every programmer had started its programming i.e printing "Hello World" on screen.

# include<stdio.h>
   main( )
{
    printf("Hello World");
}

In above program  #include directive tells the preprocessor to treat the contents of specified files as if those contents had appeared in the source program at the point where directive appears.
"stdio.h" is standard input output library and always written inside "< >" i.e. <stdio.h>
printf( ) is the command which can be used to print what user wants, it prints exactly matter which is inserted into " " . i.e in above example printf(" Hello World") .Whose output is Hello World.
Always remember to end every statement in C program with " ; " semi colon or you will get syntax error.
Also every function( ) opens with "{" bracket and ends with "}" .
So now you can try your first program in C.

Friday, August 19, 2011

Introduction to C

C , a programming language which is one of the famous and widely used programming language of all the time of its kind in the world.Dennis M. Ritchie had developed this language in the Bell Laboratories at New Jersey in the 1970's.Which was firstly developed for Unix operating system,eventually become general programming language and also has been called as mother of other famous programming language ,most noted C++ which is extended version of C.
C is also called as mid-level language as its work with low level i.e. machine language and high level language.As C can interact directly with hardware that's why it is one of the favourite language of system programmers.So this language is widely used in development of operating system,OS like Unix & Linux were entirely written in C.
Below are its advantage which makes C a popular Language:-
1.Its a fast programming language
2.Simple to understand
3.Easy to remember keywords
4.Can be used for both system development and application development.
5.Mid-level language.