Translate

Friday, 2 November 2012

Introduction to c:
    

       c is a programming language developed at Bell Laboratories of USA in 1972. it was designed and written by a man named Dennis Ritchie. 

       Literals/Constants

      the value or quantity that never change during the execution of the program is known as constant value.

types:
  1. Integer Constant
  2. Real Constant
  3. Character Constant
  4. String Constant   
1). Integer Constant:-                      a value without decimal point is known as integer constant.
        its types:
         a). Decimal Integer Constant:-
                          it cab have digit from 0 to 9 e.g. 23,89 etc.

         b). Octal Integer Constant:-
                          it can have digits from 0 to 7 and also starts from 0(zero). e.g. 023 etc.

         c). Hexadecimal Integer Constant:- 
                          it can have digits from 0 to 9 and A to F but starts from 0x.
                                                                   e.g. 0x23,0x85AB etc.
                    
2). Floating point /Real Constant:-

                                   
                      A value having decimal points. its types are
          a). Decimal Type:- 
                              eg. 2.0,3.07 etc.

          b). Exponential Type:- 
                             eg. 5.6Ed,5.6e-5

3).Character Constants:

          A Single digit or a single alphabet or any special symbol enclosed within single quotes is known as character constant. e.g. 'A','a','2','*' etc.

          there are 256 character constants in c/c++ and each having a pre assigned value called ASCII value. It occupy one byte space in memory.

4). String Constant:-

                  A Single digit or a single alphabet or any special symbol enclosed within double quotes is known as String Constant.
           e.g. "A","b","Mohit" etc.
  Each String Constant terminates with NULL character(\0). It automatically Inserted by the compiler at the end of the string. e.g. "bce"  it becomes in memory"bce\0"  
  

  Array:-

   Array is an ordered collection of homogeneous types of data elements. here by homogeneous we mean elements/values of same type i.e. int or float or char etc and by ordered we mean data is stored at continuous memory locations.
generally array is used to store and process bulk amount of data easily and efficiently. for e.g. to store and purchase bulk amount of data easily and efficiently.

types of array:-

1. 1-dimensional array:-

variable declared using single subscript is known as 1-d array.
eg. int a[4];
// different declaration cum initialization methods:
int a[]={2,4,6}; // occupy three locations 
int a[]; // invalid declaration
int a[3]={3,5}; // 3rd location will be zero
int a[3]; // all will be garbage value
static in a[3]; // all values will be zero
int[n]; // variable are not allowed in subscript

2. 2-dimensional array:- 
variable declared using two subscript is known as 2-d array. as shown below:

datatype variable[rows][column];

eg. int a[2][3];

Thursday, 1 November 2012

data types:

      data types of a variable determine the type of constant a variable can store.
types of data types:
1. Fundamental / Primitive Data Type
2. Array
3.void
4.User Defined Data Types

VioSoftware.com
variable :
        variable is a storage location in the memory used to store some constant value. its value can be changed at run time.

Identifier:

      Identifier is fancy term used to mean "name". In C, identifier are used to refer to a number of things. It is used as a name of variable and Functions.

Rules for Identifier:
1). It Should start from Alphabet(Upper/lower) or underscore only.
 eg. Abc,hHk,h12,basic_sal(Valid),
12Basicsel(Invalid)
2).Upper Case and Lower case are considered different eg. int Bat,bat;(valid)
3). Key words are not allowed 
        eg. int float=45;(invalid)
             int Float=45;(valid) 

Key Words: 
             Key word refers to the reserved words in c/c++ which can't be used as a name of the variable etc.
 list of some of keyword:
  auto   const     double  float  int       short   struct   unsigned
break  continue  else    for    long      signed  switch   void
case   default   enum    goto   register  sizeof  typedef  volatile
char   do        extern  if     return    static  union    while

Tuesday, 30 October 2012

Structure


 structure is a collection of heterogeneous types of data elements. here by heterogeneous we mean elements of different data types. i.e. int, float, char etc.


Syntax:
  struct name
       {
             dataType-1 var;
             dataType-2 var;
             ...............
        };

  it is also called User Defined Data Type. In other words using keyword struct we can create our own data types.

Monday, 29 October 2012

Functions


  Function is a named set of statements doing a particular job within the program. A program have many function and they can call to each other.

Types of functions:
1. library functions: functions defined in the language library are called library functions. eg. printf(),Scanf(),getch() etc.

2. user Defined Functions: functions defined by the users according to need are called user defined functions.

Sunday, 28 October 2012

decision making Statements:


    decision Making Statements are used to make a choice among a no. of options eg. to check weather the number is +ve or -ve, too find the division of Student ie. Ist, 2nd or Fail.

Types:

a) 
If condition only: It execute the statement if given condition evaluate true.

Syntax: 

  if(TRUE)
{
    Statements
}

b)
else-if: if condition evaluate is true then execute if block and if condition is false then execute else block. we can also say that it is used to make choice between 2 options only. eg. to check student is pass or fail.


Syntax: 

  if(TRUE)
{
    Statements;
}

else

{
    Statements;
}

  in this we not need to give any condition in else because else means it is opposite to the condition given in  if.

c)
Ladder If-else: Used to make choice among more than two options.
 if(condition)
{
   statement;
}
else if(condition)
{
   statement;
}

else if(condition)
{
   statement;
}
else
{
  statement;
}

d)
Nested If else: It is also used to make choice among more than 2 options. in this if-else statements are nested in if and else blocks.

Syntax:

if(condition)
     {

              if(TRUE)
                     {
                          Statements;
                      }

              else

                      {
                           Statements;
                       }

      }
else
     {

              if(TRUE)
                    {
                         Statements;
                     }

             else

                    {
                          Statements;
                    }

      }

program to check given number is positive or negative:


#include<iostream.h>
#include<conio.h>
void main()
{
   clrscr();
   int n;
   cout<<"Enter any number\n";
   cin>>n;
   if(n<0)
     {
          cout<<"Given number is negative";
      }
   else
      {
           cout<<"Given number is positive";
       }
getch();
}

Wednesday, 24 October 2012

Program for Concatenation of two strings

#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
   {
     char st[20];
     public:
void input()
    {
cout<<"\nEnter the string=";
cin.getline(st,20);
    }
     string operator+(string s)
   {
     string temp;
     strcpy(temp.st,st);
     strcat(temp.st,s.st);
     return temp;
   }
     void output()
   {

     cout<<"\nThe string is="<<st;
   }
   };
void main()
      {
string s1,s2,s3;
clrscr();
s1.input();
s2.input();
s3=s1+s2;
s3.output();
getch();
      }

Thursday, 11 October 2012



\\Program for finding the given number is even or odd

#include<iostream.h>
#include<conio.h>
void main()

    {

      clrscr();
      int n;
      cout<<"Enter the number=";
      cin>>n;
      if(n%2==0)
cout<<"\n\nGiven number is even";
      else
cout<<"\n\nGiven number is Odd";
      getch();
    }

Saturday, 6 October 2012

Welcome to C/C++

#include<iostream.h>
#include<conio.h>
void main()
   {
         clrscr();     // clear the output screen
         cout<<"welcome to C/C++";  // print on screen
         getch();                                   // ask for enter any character
   }

Sunday, 30 September 2012

Pointers:

  Pointers are Special Type of variables which are used  to store the Address of Another variable or memory location. Using a pointer variable we can access and modify the value of  a variable of which it consists the address. A pointer variable can hold the address of one memory location at a time.

      the data type of pointer variable and the variable of which it consist the address should be same.


Syntax:

       dataType *ptrVariable;


note: we can't perform Arithmetic operations on Addresses except Subtraction.

    For example:

      int a,b;
 =&a+&b;(Invalid)