C /C++


/*---------------------------C Language-----------------------------*/
/*-------------------------------------------------------------------------*/

/*-----Creating Custom Header File----------*/
First i create a header file name is sample.h
int sum(int x,int y);
float average(float x,float y,float z);
After that i create a file name is sample.c
int sum(int x,int y)
{
return(x+y);
}
float average(float x,float y,float z)
{
return((x+y+z)/3);
After that i write a file name is example.c
#include<stdio.h>
#include"sample.h"
main()
{
int thesum=sum(10,10);
float theaverage=average(2.3,5.7,88,5);
printf("%i",thesum);
printf("%f",theaverage);
getch();
return 0;
}



WAP Prime or Not Prime
/*-------------------------*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,c=0;
clrscr();
printf("enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
   {
     if(n%i==0)
       {
         c=c+1;
        }
   }
if(c==2)
printf("number is prime");
else
printf("number is not prime");
getch();
}
/*------------Recursion Function-------------*/

#include <stdio.h>
#include <conio.h>

Recursion()
{
int no;
printf("\nRecursion... ");
printf("\n\n Enter Number : ");
scanf("%d",&no);
if (no==3)
exit(0);
else
Recursion();
}
int main()
{

Recursion();
return 0;
}

/*------------------Call By Reference----------------------*/

#include<stdio.h>
 
void swap(int*, int*);
 
main()
{
   int x, y;
 
   printf("Enter the value of x and y\n");
   scanf("%d%d",&x,&y);
 
   printf("Before Swapping\nx = %d\ny = %d\n", x, y);
 
   swap(&x, &y); 
 
   printf("After Swapping\nx = %d\ny = %d\n", x, y);
 
   return 0;
}
 
void swap(int *a, int *b)
{
   int temp;
 
   temp = *b;
   *b = *a;
   *a = temp;   
}


/*------------Find Revers Using Array-------*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char a[5];
printf("Enter String");
for(i=0;i<=4;i++)
{
   scanf("%c",&a[i]);             
}    
for(i=4;i>=0;i--)
{
   printf("%c",a[i]);             
}
getch();
}


/*------------Matrix Addition----------------*/


#include<stdio.h> 
#include<conio.h> 
#include<math.h> 
void main() 
{ 
int a[4][4],b[4][4],c[4][4],i,j; 
printf("enter the elements of matrix a"); 
for(i=0;i<=3;i++) 
for(j=0;j<=3;j++) 
scanf("%d",&a[i][j]); 
printf("the first matrix is"); 
for(i=0;i<=3;i++) 
{ 
printf("\n"); 
for(j=0;j<=3;j++) 
printf("%d",a[i][j]); 
} 
printf("Enter the elements of second matrix"); 
for(i=0;i<=3;i++) 
for(j=0;j<=3;j++) 
scanf("%d",&b[i][j]); 
printf("the second matrix is"); 
for(i=0;i<=3;i++) 
{ 
printf("\n"); 
for(j=0;j<=3;j++) 
printf("%d",b[i][j]); 
} 
for(i=0;i<=4;i++) 
for(j=0;j<=4;j++) 
c[i][j]=a[i][j] + b[i][j]; 
printf("the addition of matrix is"); 
for(i=0;i<=3;i++) 
{ 
for(j=0;j<=3;j++) 
printf("%d\t",c[i][j]); 
printf("\n"); 
} 
getch(); 
}

/*----------Matrix Multiplication-----------*/

#include <stdio.h>

void main()
{
   int m, n, p, q, c, d, k, sum = 0;
   int first[10][10], second[10][10], multiply[10][10];

   printf("Enter the number of rows and columns of first matrix\n");
   scanf("%d%d", &m, &n);
   printf("Enter the elements of first matrix\n");

   for (  c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         scanf("%d", &first[c][d]);

   printf("Enter the number of rows and columns of second matrix\n");
   scanf("%d%d", &p, &q);

   if ( n != p )
      printf("Matrices with entered orders can't be multiplied with each other.\n");
   else
   {
      printf("Enter the elements of second matrix\n");

      for ( c = 0 ; c < p ; c++ )
         for ( d = 0 ; d < q ; d++ )
            scanf("%d", &second[c][d]);

      for ( c = 0 ; c < m ; c++ )
      {
         for ( d = 0 ; d < q ; d++ )
         {
            for ( k = 0 ; k < p ; k++ )
            {
               sum = sum + first[c][k]*second[k][d];
            }

            multiply[c][d] = sum;
            sum = 0;
         }
      }

      printf("Product of entered matrices:-\n");

      for ( c = 0 ; c < m ; c++ )
      {
         for ( d = 0 ; d < q ; d++ )
            printf("%d\t", multiply[c][d]);

         printf("\n");
      }
   }

}

What is c?
Structured Based programming languages
Examples-
#include<stdio.h>
#include<conio.h>
void main()
{
     printf("Hello");
     getch();
 }
Note #-Preprocessor
Dev C++ IDE
Short Keys-Compilation ctr+F9
                Run ctr+F10
C comments
Which statement that not read or execute by the Compiler called comments.
Types of comments:-
1 Single Line Comments (//Statements)
2 Multi Line Comments (/*Statements*/)
 What is Header Files?
Logical Grouping of Function Called Header Files.
Example-
Stdio.h
Conio.h
Math.h
String.h
What is Data Type?
Category of Data called Data Type.
  1. Integer
  2. Floating
  3. Character
  4. Boolean
Specifies in C Language?
1 Integer
                short 2byts -%d
                Int 2byts-%d
                long 4 byts-%l
2 Floating
 float 4bytes %f
double 8bytes %f
3 Character
char 1 byte %c
4 Boolean
                bool 1 byte
Example WAP Sum of two integer number.
#include<stdio.h>
#include<conio.h>
void main()
{
     int a,b;
     int sum;
     //clrscr();
     printf("\n Enter The a=");
     scanf("\n %d",&a);
     printf("\n Enter The b=");
     scanf("\n %d",&b);
     sum=a+b;
     printf("\n The Sum=%d",sum);
     getch();
 }
Example WAP Find The ASCII Code of keyboard key.
#include<stdio.h>
#include<conio.h>
void main()
{
     char n;
     printf("Enter Value=");
     scanf("%c",&n);
     printf("THE ASCII Value=%d",n);
     getch();
 }
What is Operators in C?
Operator performs some operation using key that called operator.
Types of Operator
1 Arithmetic Operator
                Addition +
                Subtraction -
                Multiplication *
                Division /
               
Example
a=a+1;
                Uninary
Addition +
                Subtraction -
                Multiplication *
                Division /
Example
a +=1;   
 2 Relation Operators
<=
>=
==
!=
3 Logical Operators
AND &&
OR ||
NOT!
Example WAP Find Gross Salary for following Conditions?
#include<stdio.h>
#include<conio.h>
void main()
{
    float bs,gs,hra;
    printf("\n Enter Basic Salary= ");
    scanf("%f",&bs);
    if(bs>=3000)
    {
                hra=(bs*10)/100;
    }
    else if(bs>=10000)
    {
                 hra=(bs*5)/100;
    }
    else if(bs>=30000)
    {
                 hra=(bs*3)/100;
    }
    gs=bs+hra;
    printf("\n The Gorss Salary=%f",gs);
    getch();
 }
Example of Relational Operator
#include<stdio.h>
#include<conio.h>
void main()
{
    float bs,gs,hra;
    printf("\n Enter Basic Salary= ");
    scanf("%f",&bs);
    if(bs==3000 || bs>3000)
    {
                hra=(bs*10)/100;
    }
    else if(bs==10000 || bs>1000)
    {
                 hra=(bs*5)/100;
    }
    else if(bs==30000 || bs>30000)
    {
                 hra=(bs*3)/100;
    }
    gs=bs+hra;
    printf("\n The Gorss Salary=%f",gs);
    getch();
 }
4 Incremental / Detrimental Operators
Prefix
                Prefic Inc (++a)
                prefic dec (--a)
Posfix
                Prefic Inc (a++)
                prefic dec(a--)
Example-
int a=5;
int b=7;
int c;
case 1 c=++a  +  ++b;
a=6
b=8
c=14
case 2 c= a++   +   b++;
a=6
b=8
c=12
5 Special Operators
Dot(.)
Colon(:)
Semi Colon(;)
Data Conversion
Some rules of data conversion
1 Converted data have in same category
2 Small size data can converted into big size data
Example
float a;
double b;
b=(double)a;
Control Statements
When the condition checks and returns some result in the form of true and false.
1 IF Statement
if(Cond)
{
statements1;
statements2;
statements3;
}
2 IF-ELSE Statements
if(Cond)
{
statements1;
statements2;
statements3;
}
else
{
statements1;
statements2;
statements3;
}
3 Nested IF Statements
if(cond1)
{
                if(cond2)
{
statements1;
statements2;
statements3;
}
else
{
statements1;
statements2;
statements3;
}
}
else
{
statements1;
statements2;
statements3;
}
4 IF-ELSE-IF Statements
if(cond1)
{
statements1;
statements2;
}
else if(cond2)
{
statements1;
statements2;
}
else if(cond3)
{
statements1;
statements2;
}
else
{
statements1;
statements2;
}
5 Switch Statements
switch(exp)
{
case 1: Statement;
break;
case 2: Statement;
break;
case 3: Statement;
break;
case 4: Statement;
break;
default: Statement;
break;
}
Example
#include<stdio.h>
#include<conio.h>
void main()
{
     int n=18,age;
     printf("Enter the Age");
     scanf("%d",&age);
     if(age==n)
     {
               printf("Voter");
     }
     else
     {
               printf("Not Voter");
     }
     getch();
}
Looping Statements
1 For Loop
2 While Loop
3 Do While Loop
1 For Loop
Syntax
for(start;end;inc/dec)
{
Statements
Statements
Statements
}
Example
#include<stdio.h>
#include<conio.h>
void main()
{
     int i;
     for(i=1;i<=10;i++)
     {
     printf("\n Hello");
     printf("%d",i);
     }
     getch();
}
Example Print a Series
#include<stdio.h>
#include<conio.h>
void main()
{
     int i,n;
     printf("Enter Ending Value=");
     scanf("%d",&n);
     for(i=1;i<=n;i++)
     {
     printf("\n%d",(2*i-1));
     }
     getch();
}
Nested For Loop
#include<stdio.h>
#include<conio.h>
void main()
{
     int i,j;
    
     for(i=1;i<=5;i++)
     {
         for(j=1;j<=i;j++)
         {
         //printf("%d",j);
         printf("*");
         }
         printf("\n");
     }
     getch();
}
Example
#include<stdio.h>
#include<conio.h>
void main()
{
     int i,j;
    
     for(i=5;i>=1;i--)
     {
         for(j=1;j<=i;j++)
         {
         printf("%d",j);
         //printf("*");
         }
         printf("\n");
     }
     getch();
}
Output
12345
1234
123
12
1
WAP For Table Printing
#include<stdio.h>
#include<conio.h>
int main()
{
int x,i,tab;
printf("Enter the number");
scanf("%d",&x);
for(i=1;i<=10;i++)
{
tab=x*i;
printf("\n 2*%d =%d",i,tab);
}
getch();
return 0;
}
WAP for factorial of n number
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,fact=1;
printf("Enter the number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("\nThe factorial is= %d",fact);
getch();
return 0;
}
WAP for Pyramid Print
#include<stdio.h>
#include<conio.h>
void main()
{
     int i,j,k,m,p;
    
     for(i=1;i<=4;i++)
     {
         //For Loop for Spacing            
         m=4-i;            
         for(k=1;k<=m;k++)
         {
              printf(" ");
         }     
         //For Loop for * Printing
         p=2*i-1;     
         for(j=1;j<=p;j++)
         {
             printf("*");
         }
         printf("\n");
     }
     getch();
}
Output
   *
  ***
 *****
*******
WAP Dynamic Pyramid
#include<stdio.h>
#include<conio.h>
void main()
{
     int i,j,k,m,p,n;
     printf("Enter the Length");
     scanf("%d",&n);
     for(i=1;i<=n;i++)
     {
         //For Loop for Spacing            
         m=n-i;            
         for(k=1;k<=m;k++)
         {
              printf(" ");
         }     
         //For Loop for * Printing
         p=2*i-1;     
         for(j=1;j<=p;j++)
         {
             printf("*");
         }
         printf("\n");
     }
     getch();
}
Example
#include<stdio.h>
#include<conio.h>
int main()
{
  int i,j,n,m;
  printf("Enter THE Number");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
                   m=1;
                   for(j=1;j<=i;j++)
                   {
                                   m=m*2;
                                  
                   }
                   printf("\n%d",m);
  } 
  getch();
  return 0;
}
WAP for print A.P series and sum of A.P series ?
#include<stdio.h>
#include<conio.h>
int main()
{
  int a,d,n,i,sum=0;
  printf("\nEnter a=");
  scanf("%d",&a);
  printf("\nEnter d=");
  scanf("%d",&d);
  printf("\nEnter n=");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
                   sum=sum+a+i*d;        
        printf("\n%d + %d * %d=%d",a,i,d,sum);
       
  } 
  printf("\nSUM=%d",sum);
  getch();
  return 0;
}
WAP for Reverse of a string ?
#include<stdio.h>
#include<conio.h>
int main()
{
    char c[5];
    printf("Enter String=");
    gets(c);
    printf("\nThe Reverse of String=%s",strrev(c));
    getch();
  return 0;
}
While Loop
Syntax
while(condition)
{
statements
statements
statements
statements
inc/dec;
}
Do-While Loop
Syntax:-
do
{
statements
statements
statements
inc/dec;
}while(condition);
Example WAP for starting 10 no sum?
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,n,sum=0;
printf("Enter the Num=");
scanf("%d",&n);
while(i<=n)
{
            sum=sum+i;
            i++;
}
printf("Sum=%d",sum);
getch();    
}
Task-1
int i=1;
while(i<=10)
{
            printf(“Hello”);
            printf(“i=%d”,i);
            i++;
}
output=?
Task-2
int i=1;
do
{
            printf(“Hello”);
            printf(“i=%d”,i);
            i++;
} while(i<=10);
output=?
Example WAP for structure printing using while loop ?
*
* *
* * *
* * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,j;
          while(i<=4)
          {
                     j=1;
                     while(j<=i)
                     {
                               printf("*");
                               j++;
                     }
                     printf("\n");
                    
                     i++;
          }
getch();    
}
What is variable?
A Variable is named memory allocation.
Exam-
int a;
What is variable declaration?
Exam-
int a;// declaration
What is variable defining?
Exam-
int a; // declaration
a=10; // defining
What is variable initialization?
Exam-
int  i=1;//Initialization
For Loop as Infinite
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
          for(;;)
          {
                   printf("\nHello"); 
          }
getch();    
}
While Loop as Infinite
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
          while(i<=4)
          {
                   printf("\nHello");  
                  
          }
getch();    
}
Muliple Declaration in for loop
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum;
         for(i=1,sum=0;i<=10;sum+=i,i++)
         printf("\n%d",sum);
        
getch();    
}
What is Function?
A Function is set of statements which may or may not be return some values.
Types of Function
1 System Define Function
Exam-
printf()
scanf()
gets()
puts()
getch()
2 User Define Function
When the function is created itself user called user define functions.
Exam-
sum()
time()
mul()
sqr()
Syntax-
<data type><fun name>(par1,par2......par n)
{
statements
statements
statements
}
User Define Function (void type)
User Define Function (None-void type)
Steps of using functions-
Step-1
Function declaration
Step-2
Function defining
Step-3
Function calling
WAP For sum of two int number using function?
//sum of two number using void type function
#include<stdio.h>
#include<conio.h>
void sum(int,int);//fun declaration
void main()
{
     int a,b;
     printf("Enter a=");
     scanf("%d",&a);
     printf("\nEnter b=");
     scanf("%d",&b);
     sum(a,b);//fun calling
     getch();
    
}
void sum(int x,int y)//fun defination
{
printf("Sum=%d",(x+y));
}
//sum of two number using Non-void type function
#include<stdio.h>
#include<conio.h>
int sum(int,int);//fun declaration
void main()
{
     int a,b,su;
     printf("Enter a=");
     scanf("%d",&a);
     printf("\nEnter b=");
     scanf("%d",&b);
     su=sum(a,b);//fun calling
     printf("%d",su);
     getch();
    
}
int sum(int x,int y)//fun defination
{
 int c=0;
 c=x+y;
 return c;
}
Swap the numbers using call by value
//sum of two number using Non-void type function
#include<stdio.h>
#include<conio.h>
void swap(int,int);//fun declaration
void main()
{
     int a,b;
     float su;
     printf("Enter a=");
     scanf("%d",&a);
     printf("\nEnter b=");
     scanf("%d",&b);
     swap(a,b);
     getch();
    
}
void swap(int x,int y)//fun defination
{
    int t;
    t=x;
    x=y;
    y=t;
    printf("After swap values are a=%d,b=%d",x,y); 
}
Recursion Function
When a function call itself that called recursion function.
Exam-
#include<stdio.h>
#include<conio.h>
void recu();
void main()
{
     recu();
     getch();                                                      
    
}
void recu()
{
     int n;
     printf("Enter No");
     scanf("%d",&n);
     if(n==5)
     {
             exit(0);
     }
     else
     {
         recu();
     }
}
WAP for factorial using recursion
#include<stdio.h>
#include<conio.h>
int fact(int);
int main()
{
    int a;
    printf("Enter No");
    scanf("%d",&a);
    printf("factorial=%d", fact(a));
    getch();
    return 0;
    
}
int fact(int n)
{
    int f=1;
    if(n!=1)
    {
    f=fact(n-1)*n;
   
   
    }
   
    return f;
   
   
}
WAP Calculator program
#include<stdio.h>
#include<conio.h>
void adition(float,float);
void mul(float,float);
void sub(float,float);
void div(float,float);
int main()
{
     float a,b;
     int n;
     printf("Enter a=");
     scanf("%f",&a);
     printf("Enter b=");
     scanf("%f",&b);
     printf("Enter your choice:\n Press 1 - for add\n Press 2 - for multiply\n Press 3 - for subtraction\n Press 4 - for divition\n");
     scanf("%d",&n);
     switch(n)
        {
        case 1:printf("adition");
        adition(a,b);
        break;
        case 2:printf("mul");
        mul(a,b);
        break;
        case 3:printf("sub");
        sub(a,b);
        case 4:printf("div");
        div(a,b);
        break;
        default:printf("wrong");
        break;         
        }
        getch();
        return 0;
        }
        void adition(float a,float b)
        {
             printf("\nsum=%f",(a+b));
        }
        void mul(float a,float b)
        {
             printf("\nmul=%f",(a*b));
        }
        void sub(float a,float b)
        {
             printf("\nsub=%f",(a-b));
        }
        void div(float a,float b)
        {
             printf("\ndiv=%f",(a/b));
        }
WAP For printing table of any number
#include<stdio.h>
#include<conio.h>
int table(int,int);//fun declaration
int main()
{
      int a,i=1;
      printf("\nEnter No: ");
      scanf("%d",&a);
      table(a,i);
      getch();
      return 0;    
}
int table(int a,int i)//fun defination
{
    if(i!=11)
    {
    printf("%d * %d = %d\n",a,i,(a*i));
    i++;
    table(a,i);
    }    
}
User Define Data Types
Structures
Unions
Enumerators
    
What is structure?
Structure is use define data types which is collection of system define data types and size of structure is addition of all data type which is define in structure.
Syntax
struct  emp
{
int id;
char name[10];
float s;
}e1,e2,e3;
Size of emp is 2+1+4=7
Example-
#include<stdio.h>
#include<conio.h>
struct emp
{
       int id;
       float s;
}e1,e2;
void main()
{
     printf("Enter emp id ");
     scanf("%d",&e1.id);
     printf("Enter emp sal ");
     scanf("%f",&e2.s);
     printf("id and salary of emp are%d and %f",e1.id,e2.s);
     getch();    
    
}
What is Union?
Union is use define data types which is collection of system define data types and size of Union is largest data size of data type which is exist in union.
Example-
#include<stdio.h>
#include<conio.h>
union student
{
       int r;
       float w;
}s1,s2;
void main()
{
     printf("Enter student roll no ");
     scanf("%d",&s1.r);
     printf("Enter student weight ");
     scanf("%f",&s2.w);
     printf("Student rollno=%d and weight=%f",s1.r,s2.w);
     getch();    
    
}
What is Array?
A rray is collection of similar data type.
Int a[5];
A[0]
A[1]
A[2]
A[3]
A[4]
size = 5* datatype=5*2=10bytes.
Array Declaration
1 Static Declaration
2 Dynamic Declarations
3 Pure Dynamic Declarations
 1 Static Declaration
int a[5]={4,5,2,1,8};
4
5
2
1
8
A[0]
A[1]
A[2]
A[3]
A[4]
2 Dynamic Declaration
int  a[5];
for(i=0;i<=4;i++)
{
scanf(“%d”,a[i]);
}
3 Pure Dynamic Declaration
using of malloc function we create pure dynamic Declaration.
ptr=(int *)malloc(n,sizeof(int));
Type of Arrays
1 One Dimensional
2 Two Dimensional
3 Multi Dimensional
4 Jagged Arrays
1 One Dimensional
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5];
int i,sum=0;
printf("Enter the Array Value");
              for(i=0;i<=4;i++)
              {
               printf("\na[%d]=",i);
               scanf("%d",&a[i]);               
              }
              for(i=0;i<=4;i++)
              {
               printf("\na[%d]=%d",i,a[i]);
             
              }
              for(i=0;i<=4;i++)
              {
               sum=sum+a[i];
              }
              printf("\n Sum =%d",sum);
      getch();            
}
Reverse of any string
#include<stdio.h>
#include<conio.h>
void main()
{
char a[5];
int i,sum=0;
            printf("Enter String=");
              for(i=0;i<=4;i++)
              {
 
               scanf("%c",&a[i]);               
              }
              for(i=0;i<=4;i++)
              {
               printf("%c",a[i]);
             
              }
              printf("Reverse String=");
              for(i=4;i>=0;i--)
              {
              printf("%c",a[i]);                              
              }
      getch();            
}
Two Dimension Array
int  a[3][3];
A[0][0]
A[0][1]
A[0][2]
A[1][0]
A[1][1]
A[1][2]
A[2][0]
A[2][1]
A[2][2]
How to take input of two dimension array
3
4
7
10
5
8
9
1
11
a[0][0]=3
a[0][1]=4
a[0][2]=7
a[1][0]=10
a[1][1]=5
a[1][2]=8
a[2][0]=9
a[2][1]=1
a[2][2]=11
How to take output of two dimension array
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3];
int i,j;
    printf("\nEnter the matrix");
    for(i=0;i<=2;i++)
    {
                     for(j=0;j<=2;j++)
                     {
                                       printf("\na[%d][%d]=",i,j);
                                       scanf("%d",&a[i][j]);
                     }
    }
    printf("Show the matrix");
    for(i=0;i<=2;i++)
    {
                     for(j=0;j<=2;j++)
                     {
                                       printf("\na[%d][%d]=%d",i,j,a[i][j]);
                     }
    }
    getch();
    
}
Searching in Array
5
4
6
3
2
8
7
9
10
14
WAP for searching the given number?
WAP for sorting the given number?
#include<stdio.h>
#include<conio.h>
void main()
{
     int a[10];
     int i,j,t;
    
    
     printf("Enter the Array");
     for(i=0;i<=9;i++)
     {
                                      printf("\na[%d]=",i);
                                      scanf("%d",&a[i]);
     }
     for(j=0;j<=9;j++)
    {
     for(i=0;i<=9;i++)
     {
                if(a[i]>a[i+1])
                {
                t=a[i];
                a[i]=a[i+1];
                a[i+1]=t;
                }
     }
    }
     for(i=0;i<=9;i++)
     {
                                      printf("\na[%d]=",i);
                                      printf("%d",a[i]);
     }
     getch();
 }
/*-----------Realloc Funtion------------*/
/*--------------------------------------------*/

#include<stdio.h>
#include<conio.h>
void main()
{
int * buffer;

/*get a initial memory block*/
buffer = (int*) malloc (10*sizeof(int));
if (buffer==NULL)
{
printf("Error allocating memory!");
exit (1);
}

/*get more memory with realloc*/
buffer = (int*) realloc (buffer, 20*sizeof(int));
if (buffer==NULL)
{
printf("Error reallocating memory!");
//Free the initial memory block.
free (buffer);
exit(1);
}
free (buffer);
getch();

}



/*---------------------------C++ Language-----------------------------*/
/*-----------------------------------------------------------------------------*/

/*----Assign Values using Pointers-----*/
#include <iostream>
void main ()
{
  int firstvalue, secondvalue;
  int * mypointer;
  mypointer = &firstvalue;
  *mypointer = 10;
  mypointer = &secondvalue;
  *mypointer = 20;
  cout << "firstvalue is " << firstvalue << endl;
  cout << "secondvalue is " << secondvalue << endl;
  }
Output
firstvalue is 10
secondvalue is 20
Note
Notice that even though we have never directly set a value to either firstvalue or secondvalue, both end up with a value set indirectly through the use of mypointer. This is the procedure:

First, we have assigned as value of 
mypointer a reference to firstvalue using the reference operator (&). And then we have assigned the value 10 to the memory location pointed by mypointer, that because at this moment is pointing to the memory location of firstvalue, this in fact modifies the value of firstvalue.

In order to demonstrate that a pointer may take several different values during the same program I have repeated the process with 
secondvalue and that same pointer, mypointer.


// classes example
#include <iostream>
#include<conio.h>
using namespace std;
class CRectangle
{
  int x, y;
  public:
    void set_values (int,int);
    int area ()
    {
        return (x*y);
    }
};
void CRectangle::set_values (int a, int b) {
  x = a;
  y = b;
}
int main ()
{
  CRectangle rect;
  rect.set_values (3,4);
  cout << "area: " << rect.area();
  getch();
  return 0;
}


/*---------Classes and Object -------------*/
/*-----------------------------------------------------*/

#include<iostream.h>
#include<conio.h>
class student
{
      public :
             int r;
             int m;
      public :
             void showRollno(int a)
             {
                  cout<<"\nStudent Roll No="<<a;
             }
             void showMark(int b)     
             {
                  cout<<"\nStudent Mark="<<m;
             }
};
int main()
{
    student s;
    cout<<"\nEnter Student Roll No";
    cin>>s.r;
   
    cout<<"\nEnter Student Marks";
    cin>>s.m;
    
    s.showRollno(s.r);
    s.showMark(s.m);
    getch(); 
    return 0;
 }
/*-----External Function Definition of Class-------*/


// classes example
#include <iostream>
#include<conio.h>
using namespace std;

class CRectangle
{
  int x, y;
  public:
    void set_values (int,int);
    int area ()
    {
        return (x*y);
    }
};

void CRectangle::set_values (int a, int b) {
  x = a;
  y = b;
}

int main ()
{
  CRectangle rect;
  rect.set_values (3,4);
  cout << "area: " << rect.area();
  getch();
  return 0;
}


/*------Inheritance------------*/


#include <iostream.h>
#include <conio.h>

class A {
   int data;
public:
   void f(int arg) { data = arg; }
   int g() { return data; }
};

class B {
public:
   A x;
};

int main() {
   B obj;
   obj.x.f(20);
   cout << obj.x.g() << endl;
   //cout << obj.g() << endl;
     getch();
     return 0;
}
/*----------Inheritance------------*/

  
#include <iostream.h>
#include <conio.h>
class BaseClass {
  int i;
public:
  void setInt(int n);
  int getInt();
};
class DerivedClass : public BaseClass {
  int j;
public:
  void setJ(int n);
  int mul();
};
void BaseClass::setInt(int n)
{
  i = n;
}
int BaseClass::getInt()
{
  return i;
}
void DerivedClass::setJ(int n)
{
  j = n;
}
int DerivedClass::mul()
{
  return j * getInt();
}
int main()
{
  DerivedClass ob;
  ob.setInt(10);        // load i in BaseClass
  ob.setJ(4);          // load j in DerivedClass
  cout << ob.mul();     // displays 40
  getch();
  return 0;
}



Stop auto-fill in browsers for textbox
 <form id="Form1" method="post" runat="server" autocomplete="off">
 <asp:TextBox Runat="server" ID="txtConfidential" autocomplete="off"></asp:TextBox>
Disable right click on web page
<body oncontextmenu="return false;" >

Disable right click on images

<img alt="MyImage" src="../ImgLoc/2.png" oncontextmenu="return false;"/> 


Show alert on right click


 <script type="text/javascript"> 
function disableRightClick() 

alert("Sorry, right click is not allowed !!"); 
return false; 

</script> 
<body oncontextmenu=" return disableRightClick();">
... 

</body> 

========================================================================

http://fresh2refresh.com/c/c-loop-control-statements/




http://www.1keydata.com/css-tutorial/clear.php
http://www.1keydata.com/css-tutorial/text.php#lineheight
https://mybizcard.co/vikash.chauhan.283612
http://www.careerealism.com/linkedin-10-tips-effectively-status-update/#chitika_close_button
http://www.aspdotnet-suresh.com/2012/07/how-to-bind-dropdownlist-in-aspnet.html
http://stackoverflow.com/questions/2612422/binding-dropdownlist-using-jquery
http://forum.jquery.com/topic/set-dropdown-list-selected-value-after-dynamically-populating
http://viralpatel.net/blogs/dynamic-combobox-listbox-drop-down-using-javascript/
http://www.dotnetperls.com/xmlreader

1 comment:

  1. .Net tutorial and source code...

    http://net-informations.com

    Ling

    ReplyDelete