Showing posts with label C Language. Show all posts
Showing posts with label C Language. Show all posts

Thursday 1 February 2018

Examples Array in C Language

1.

#include<stdio.h>
int main()
{
    int a[5],sum=0,i;
    for(i=0;i<5;i++)
    {
        printf("Enter the no.");
        scanf("%d",&a[i]);
    }
    for(i=0;i<5;i++)
    {
        sum=sum+a[i];
    }
    printf("sum=%d",sum);
}


2.

#include<stdio.h>
int main()
{
    int a[10],i;
    for(i=0;i<10;i++)
    {
        printf("Enter the no ");
        scanf("%d",&a[i]);
    }
    for(i=9;i>=0;i--)
    {
        printf("\n%d",a[i]);
    }
}


3.

#include<stdio.h>
int main()
{
    int i;
    int a[4],b[4],c[4];
    for(i=0;i<4;i++)
    {
    printf("Enter the a = ");
    scanf("%d",&a[i]);   
    }
    for(i=0;i<4;i++)
    {
    printf("Enter the b = ");
    scanf("%d",&b[i]);   
    }
    for(i=0;i<4;i++)
    {
    c[i]=a[i]+b[i];
    printf("\t%d",c[i]);
    }
}


4.

#include<stdio.h>
int main()
{
    int a[5],g=0,p,i;   
    for (i=0;i<5;i++)
    {
    printf("Enter the no = ");
    scanf("%d",&a[i]);
    }
    for(i=0;i<5;i++)
    {
        if(g<a[i])
        {
            g=a[i];
            p=i+1;
        }
    }
    printf("Greatest = %d",g);
    printf("Position of no. = %d",p);
}


5.

#include<stdio.h>
int main()
{
    int i,j;
    int a[3][4],b[3][4],c[3][4];   
    for(i=0;i<3;i++)
    {
        for(j=0;j<4;j++)
        {
        printf("Enter the a = ");
        scanf("%d",&a[i][j]);   
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<4;j++)
        {
        printf("Enter the b = ");
        scanf("%d",&b[i][j]);
        }
    }   
    for(i=0;i<3;i++)
    {
        for(j=0;j<4;j++)
        {
        c[i][j]=a[i][j]+b[i][j];
        printf("\t%d",c[i][j]);
        }
        printf("\n");
    }
}


6.

#include<stdio.h>
int main()
{
    int i,j;
    int a[3][4];
    for(i=0;i<3;i++)
    {
        for(j=0;j<4;j++)
        {
        printf("Enter the no= ");
        scanf("%d",&a[i][j]);
        }
        printf("\n");
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<4;j++)
        {
            printf("\t%d",a[i][j]);
        }
        printf("\n");
    }
}

Examples Function in C Language

1.

#include<stdio.h>
int main()
{
    int power(int,int);
    int p,a,b;
    printf("Enter the no. ");
    scanf("%d",&a);
    printf("Enter The Power ");
    scanf("%d",&b);
    p=power(a,b);
    printf("p=%d",p);
}
power(int x,int y)
{
    int i,a=1;   
    for(i=1;i<=y;i++)
    {
        a=a*x;
    }
    return(a);
}


2.

#include<stdio.h>
int main()
{
    float area (float);
    float aoc,r;
    printf("Enter the circle of radius .");
    scanf("%f",&r);
    aoc=area(r);
    printf("aoc=%f",aoc);
}
area(float rad)
{
    float a,pi=3.14;
    a=pi*rad*rad;
    return(a);
}


3.

#include<stdio.h>
int main()
{
    void avg(int,int);
    int a,b;
    printf("Enter the number");
    scanf("%d%d",&a,&b);
    avg(a,b);   
}
sum(int x,int y)
{
    int z;
    z=x+y;
    return(z);
}
avg(int p,int q)
{
    float r,av;
    r=sum(p,q);
    av=r/2;
    printf("\nSum=%f",r);
    printf("\nAvg=%f",av);
}


4.

#include<stdio.h>
int main()
{
    int prime(int);
    int a;
    printf("Enter the no = ");
    scanf("%d",&a);
    prime(a);
}
prime(int a)
{
    int i,y,x=0;
    if((a==1)||(a==2))
    {
        printf("prime no");
    }
    else
    {
        for(i=2;i<a;i++)
        {
            if((a%i)==0)
            {   
                x=1;
                y=i;
                printf("\n no is divid by %d",y);
            }
        }
        if(x==1)
        {
            printf("\nThen no is not prime");
        }
        else
        {
            printf("prime no");   
        }
    }
}


5.

#include<stdio.h>
float c;
sum(float a,float b)
{
    c=a+b;
    return(c);
}
diff(float a,float b)
{
    c=a-b;
    return(c);
}
mul(float a,float b)
{
    c=a*b;
    return(c);
}
div(float a,float b)
{
    c=a/b;
    return(c);
}
mod(int a,int b)
{
    int d;
    d=a%b;
    return(d);
}
int main()
{
    int ch,d,x,y;
    float a,b;
    printf("for sum prace 1,for deffrence prace 2,for mul prace 3,for division prace 4,for modlus prace 5");
    printf("\nEnter the ch=");
    scanf("%d",&ch);
    switch(ch)
    {
    case 1:
        printf("Enter the no=");
        scanf("%f%f",&a,&b);
        c=sum(a,b);
        printf("Sum=%f",c);
        break;
    case 2:
        printf("Enter the no=");
        scanf("%f%f",&a,&b);
        c=diff(a,b);
        printf("Diff=%f",c);
        break;
    case 3:
        printf("Enter the no=");
        scanf("%f%f",&a,&b);
        c=mul(a,b);
        printf("Mul=%f",c);
        break;
    case 4:
        printf("Enter the no=");
        scanf("%f%f",&a,&b);
        c=div(a,b);
        printf("Div=%f",c);
        break;
    case 5:
        printf("Enter the no=");
        scanf("%d%d",&x,&y);
        d=mod(x,y);
        printf("Mod=%d",d);
        break;
    default:
        printf("Wrong Choice");
       
    }
}


Example Recursive Function in C Language

Write a program to calculate the factorialof a positiv intger using recursive function.

long int fact(n)
int n;
{
long int result;
if(n==0)
result=1;
else
result=n*fact(n-1);
return (result);
}
voidmain( )
{
int I;
for(i=0;i<10;i++)
{
printf(“%d\n”,i,fact(i));
}
}



Output:

0!=1
1!=1
2!=2
3!=6
4!=24
5!=120
6!=720
7!=5040
8!=40320
9!=362880
10!=3628800

Example do-While Loop in C Language

1.Write a program to evaluate the factorial value of a integer no.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int n,i,fact=1;
printf(“enter the no”);
scanf(“%d”,&n);
i=1;
if(n>1)
do
{
fact=fact*i;
i++;
}
while(i<=n);
printf(“\n factorial value=%d”,fact);
getch( );
}

Output:

enter the no 9
factoria value=362880

2.Write a program find out the table of the intger no.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int n,m,I;
printf(“enter the no”);
scanf(“%d”,&n);
i=1;
do
{
m=n*I;
printf(“%d%d=%d”,n,I,m);
i++;
}
while(i<=10);
getch( );
}

Output:

Enter the no 9
9*1=9
9*2=18
9*3=27
9*4=36
9*5=45
9*6=54
9*7=63
9*8=72
9*9=81
9*10=90

Example for Loop in C Language

1.Write a program to evaluate the factorial value of a integer no.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int n,i,fact=1;
printf(“enter the no”);
scanf(“%d”,&n);
if(n>1)
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf(“\n factorial value=%d”,fact);
getch( );
}

Output:

enter the no 6
factoria value=720

2.Write a program tofind out the sum of n integer numbrs.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int n,i,sum=0;
printf(“enter the no”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf(“\n sum=%d”,sum);
getch( );
}

Output:

enter the no 20
sum=210

3.Write a program find out the table of the intger no (using for loop).

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int n,m,I;
printf(“enter the no”);
scanf(“%d”,&n);
for(i=1;I<=n;i++)
{
m=n*I;
printf(“%d%d=%d”,n,I,m);
}
while(i<=10);
getch( );
}

Output:

Enter the no 5
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25
5*6=30
5*7=35
5*8=40
5*9=45
5*10=50

4.Write a program to calculates fabonacii series.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int a=0,b=1,I,c,n;
printf(“enter the no”);
scanf(“%d”,&n);
printf(“%d”,a);
printf(“%d”,b);
printf(“%d”,b);
for(i=1;i<=n;i++)
{
C=a+b;
printf(“\t%d”,c);
a=b;
b=c;
}
printf(“\n n=%d”,n);
getch( );
}

Output:

enter the no 10
0 1 1 2 3 5 8 13 21 34 55 89 144
n=10

Example While Loop in C Language

1.Write a program to evaluate the factorial value of a integer no.


#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int n,i,fact=1;
printf(“enter the no”);
scanf(“%d”,&n);
i=1;
if(n>1)
while(i<=n)
{
fact=fact*i;
i++;
}
printf(“\n factorial value=%d”,fact);
getch( );
}

Output:

enter the no 5
factoria value=120


2.Write a program tofind out the sum of n integer numbrs(using while loop).

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int n,i,sum=0;
printf(“enter the no”);
scanf(“%d”,&n);
i=1;
while(i<=n)
{
sum=sum+i;
i++;
}
printf(“\n sum=%d”,sum);
getch( );
}

Output:

enter the no 100
sum=5050

Example Switch Statement in C Language

Write a program to calculate the addition, subtraction, multiplication and division of two integer number using switch statement.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
float a,b,c;
int n;
printf(“enter the value of a,b and n”);
scanf(“%f%f%d”,&a,&b,&n);
switch(n)
{
case 1:
c=a+b;
break;
case 2:
c+a-b;
break;
case 3:
c=a*b;
break;
case 4:
c=a/b;
break;
defult:
printf(“value is not valid”);
}
Printf(“\n c=%f”,c);
getch( );
}


Output:

enter the value of a,b and n 2 4 1
c=6.00

enter the value of a,b and n 2 4 2
c=-2.00

enter the value of a,b and n 2 4 3
c=8.00

enter the value of a,b and n 2 4 4
c=2.00

enter the value of a,b and n 2 4 6

value is not valid

Example if and if-else Conditions in C Language

1.Two integer numbers are input through the keybord. Write a program find out the greater no.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int x,y;
printf(“enter the no”);
scanf(“%d%d”,&x,&y);
if(x>y)
printf(“x is greater”);
if(y>x)
printf(“y is greater”);
getch( );
}

Output:

enter the no 20
16
x is greater
enter the no 6
8
y is greater


2.Write a program find out the no is even or odd.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int a;
printf(“enter the no”);
scanf(“%d”,&a);
if(a%2==0)
printf(“even no”);
if(a%2!=0)
printf(“odd no”);
getch( );
}


Output:

enter the no 22
even no

enter the no 11
odd no

3.Write a program to find out year is leap year or not.

#include<stdio.h>
int main()
{
    int year;
    printf("enter the year=");
    scanf("%d",&year);
    if(year%400==0)
    {
        printf("year is leap year");
    }
    else if((year%100!=0)&&(year%4==0))
        {
        printf("year is leap year");
        }
        else
        {
        printf("year is not leap year");
        }
}   

Output:

enter the year= 2000
year is leap year

enter the year= 1999
year is not leap year


4.Three integer numbers are input through the keybord. Write a program find out the greater no.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int x,y,z;
printf(“enter the no”);
scanf(“%d%d%d”,&x,&y,&z);
if(x>y&&x>z)
printf(“x is greater”);
if(y>z&&y>x)
printf(“y is greater”);
else
printf(“z is greater”);
getch( );
}

Output:

enter the no 6 5 4
x is greater
enter the no 7 10 6
y is greater
enter the no 100 200 201
z is greater


Example (C Language Simple Programs)


1.Write a program to calculate sum of two numbers.


#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int n1,n2,sum;
printf(“enter the value of n1 and n2”);
scanf(“%d%d”,&n1,&n2);
sum=n1+n2;
printf(\n sum=%d”,sum);
getch( );
}

Out put:
enter the value of n1and n2 4
5
sum=9

2.Write a program to find out the area of circle.

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
float r,aoc;
float pie=3.14;
printf(“enter the radius of a circle”);
scanf(“%f”,&r);
aoc=pie*r*r;
printf(“\n area of circle=%f”,aoc);
getch( );
}

Out put:
enter the radius of a circle 6
area of circle=113.04

3.Write a program to find the maturity value of a principal P due to the rate of compound interest r% using the formula.
Maturity=p(1+r/100)^n


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
clrscr( );
float m,p,n,r,v,s;
printf(“enter the value of principal,rate and time”);
scanf(“%f%f%f”,&p,&r,&n);
v=(1+r/100);
s=pow(v,n);
m=p*s;
printf(“\n maturity=%f”,m);
getch( );
}

Output:
enter the value of principal,rate and time
1000
6
3Maturity=1191.015869

Recursion in C Language

C language में recursion एक ऐसी process होती है जिसमें एक function खुद को ही call करता है। ऐसा किसी problem को small parts में divide करके solve करने के लिए किया जाता है। ऐसे functions जो स्वयं को call करते है उन्हें recursive functions कहा जाता है।
मान लीजिये आप किसी problem को solve करने के लिए कोई function create कर रहे है और इसका जो initial result है वो end result नहीं है। End result प्राप्त करने के लिए आपको इस process को वापस repeat करने की आवश्यकता है। ऐसी situation में आप same process execute करने के लिए iteration करने के बजाय इसी function को शुरूआती result के साथ call करते है। जब तक end result नहीं प्राप्त हो जाता यह process चलती रहती है। End result को condition द्वारा determine किया जाता है। End result प्राप्त होने पर इस process को terminate कर दिया जाता है। यदि इस function को terminate नहीं किया जाता है तो ये infinite time तक चलता जायेगा।



The following example generates the Fibonacci series for a given number using a recursive function.

#include <stdio.h>

int fibonacci(int i) {

   if(i == 0) {
      return 0;
   }

   if(i == 1) {
      return 1;
   }
   return fibonacci(i-1) + fibonacci(i-2);
}

int  main() {

   int i;

   for (i = 0; i < 10; i++) {
      printf("%d\t\n", fibonacci(i));
   }

   return 0;
}

Function in C Language

किसी भी C प्रोग्राम में कम से कम एक फंक्शन main() तो होता ही है इसके अलावा अन्य प्रोग्राम में और भी फंक्शन होते हैं । फंक्शन बना कर coding करने से कई लाभ होते हैं जैसे एक ही प्रकार के टास्क के लिए हमें बार बार कोडिंग  नहीं करनी पड़ती  बस हमें उस फंक्शन को ही हर बार कॉल करना होता है | बड़े प्रोग्राम में एरर की बहुत सम्भावना होती है पर जब हम इससे कई छोटे छोटे फंक्शन में बाँट कर लिखते हैं  तब हमारी पकड़ बहुत अच्छी होती है और गलतियों की सम्भावना बहुत काम होती है ।

Built-in Function

हमें बहुत सारे फंक्शन कि के साथ भी मिलते हैं जिन्हें हम बिल्ट इन  फंक्शन कहते हैं इनको अलग अलग केटेगरी के हिसाब से अलग अलग लाइब्रेरी फाइल में डिफाइन किया गया है जब जिस प्रकार के फंक्शन को इस्तेमाल करना होता है उस कटेगरी की हेडर फाइल को अपने कोड में include करके हम उन फंक्शन का इस्तेमाल कर सकते हैं । जैसे input और  output से सम्बंधित फंक्शन इस्तेमाल करने के लिए हमें standard input and output header file include करनी पड़ती है इसलिए हम  #include <stdio.h> लिख कर इस फाइल को अपने कोड में ऐड कर लेते हैं ।

User Defined Function

जो फंक्शन हम अपने प्रोग्राम में अपनी जरूरत के अनुसार डिफाइन करते हैं या बनाते हैं उन्हें यूजर डिफाइंड फंक्शन कहते हैं । जब हम फंक्शन डिफाइन की बात करते हैं तो हम मूल रूप से फंक्शन हेडर और फंक्शन बॉडी की बात करते हैं । यहां पर हम फंक्शन सभी भागों के बारे में बात करेंगे । जैसे  Return type , function name , parameter और  function body.

Example

int sumoftwonum(int ,int ); //function prototype

int sumoftwonum(int a,int b) { // function definition

int c=0;
c = a + b;

return c;
}

int finalsum = sumoftwonum(6,5); // function calling


function prototype – यह पार्ट सबसे ऊपर लिखा जाता है इस पार्ट से कम्पाइलर को मालूम पड़ता है कि इस नाम का फंक्शन नीचे डिफाइन किया गया है ।

function define – इस पार्ट में फंक्शन में क्या होगा इसके लिए कोडिंग की जाती है |

Explanation – इसमें sumoftwonum function name है और उसके बाद ब्रैकेट में दो बार int लिखा गया है जिसका अर्थ है की इस function में हमें दो  int value parameter या argument के रूप में भेजनी पड़ेंगी । लाइन में सबसे पहले भी int लिखा गया है इसका अर्थ है कि यह function run होने के बाद एक int value return करेगा ।


function call – इस पार्ट में फंक्शन को कॉल किया जाता है या हम ये भी कह सकते हैं की इसी स्टेटमेंट के बाद ही फंक्शन कार्य करना शुरू करता है ।

Function में दो प्रकार के Parameters होते है |

1.Formal Parameter
2.Actual Parameter

1.Formal Parameter

जो parameter function के declaration में और definition में लिखे जाते है, उसे Formal Parameter कहते है |

for eg.

void swap(int x, int y); // Formal Parameters
int main(){
int a=2; b=10
swap (a, b)
}
void swap (int x, int y){    //Formal Parameters
------------
------------
}

2.Actual Parameter

जो parameter function call में लिखे जाते है, उसे Actual Parameter कहते है |

for eg.

void swap(int x, int y);
int main(){
int a=2; b=10
swap (a, b)    //Actual Parameter
}
void swap (int x, int y){
------------
------------
}

Function Calling के दो प्रकार है |

1.Call By Value
2.Call By Reference


1. Call By Value

Call By Value में Variable के value को parameter के रूप से function को pass किया जाता है | और Actual Parameter की value Formal Parameter पर copy की जाती है  |

for eg.
void swap(int x, int y);

int main(){
   
int a = 2, b = 10;
printf("Before Swapping  a = %d and b = %d\n", a, b);
swap(a, b);
}
void swap(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
printf("After Swapping a = %d and b = %d", x, y);
}


यहाँ पर Program में variable 'a' और 'b' function 'swap' को pass किये गए है | यहाँ पर 'a' और 'b' की values 'x' और 'y' variable पर copy की जाती है |
 
2. Call By Reference
 

Call By Reference में Variable के address को parameter के रूप से function को pass किया जाता है | और Actual Parameter की value Formal Parameter पर copy नहीं की जाती है  |


for eg.

void swap(int *x, int *y);

int main(){
   
int a = 2, b = 10;
printf("Before Swapping  a = %d and b = %d\n", a, b);
swap(&a, &b);
}
void swap(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
printf("After Swapping a = %d and b = %d", *x, *y);
}


यहाँ पर Program में variable 'a' और 'b' के address को function 'swap' को pass किया  गया है | यहाँ पर 'a' और 'b' की values 'x' और 'y' variable पर copy नहीं की जाती है |
 

String in C Language

Strings characters का समूह होता है | Strings One-dimensional array होता है, जिसमे सिर्फ characters होते है | String का आखिरी character 'NULL'(\0) होता है | अगर पूरा string लिखना हो तो उसे double quotes ( " " ) में लिखा जाता है | अगर एक-एक character को लिखना हो तो उसे single quotes ( ' ' ) में लिखा जाता है | String का data type character (char) होता है 

Example for Single Character String

char str1[6] = {'H', 'e', 'l', 'l', 'o', '\0'}; 

Example for Multiple Character String

char str2[6] = "Hello"; 

String Working with size (sizeof)

Program में हर एक String के initialization में अलग-अलग size है | दिए हुए array के size की memory allocate की जाती है | अगर Array का size नहीं दिया जाता तो जितनी size string की है उतनी size array allocate करता है |


String Library Functions

इन Functions को Program में इस्तेमाल करना हो तो string.h या strings.h इन header file को include करना पड़ता है |


String FunctionDescription
strcatएक String से दूसरे String को जोड़ा जाता है |
strchrदिए हुए string से एक character का पहला occurrence के आगे का string pointer को return करता है |
strcmpदो String को Compare किया जाता है | ये case-sensetive है |
strcmpiदो String को Compare किया जाता है | ये case-sensetive नहीं है |
strcpyएक string को दूसरे string में copy करता है |
strdupString का duplicate बनाता है |
strlenString की Length निकाली जाती है |
strlwrUppercase के Characters को Lowercase में convert किया जाता है |
strncatदिए हुए number के जितने character है उनसे String को जोड़ा जाता है |
strncpyदिए हुए number के जितने character एक string से दूसरे string में copy किया जाता है |
strnsetदिए हुए number और दिए हुए character के हिसाब से string को replace करता है |
strrchrदिए हुए string से एक character का आखिरी occurrence के आगे का string pointer को return करता है |
strrevString को उलटी दिशा से print करता है |
strrstrदिए हुए String का आखिरी string occurrence के आगे का string pointer को return करता है |
strsetदिए हुए character से पूरे string को replace करता है |
strstrदिए हुए String का पहला string occurrence के आगे का string pointer को return करता है |
struprLowercase के Characters को Uppercase में convert किया जाता है |

strcat() - String Function

strcat ये String का एक Function है | एक String से दूसरे String को जोड़ा जाता है |
 
Syntax for strcat()

strcat(destination_string, source_string);

strchr() - String Function

दिए हुए string से एक character का पहला occurrence के आगे का string pointer को return करता है |

Syntax for strchr()

strchr(string, int character);

string - ये एक normal string है |
int character - ये दिए हुए string में से दिए हुए character का पहला occurrence के आगे का string pointer को return करता है |
अगर दिया हुआ character string को नहीं मिलता तो वो NULL character return करता है |

strcmp() - String Function

दो String को Compare किया जाता है | ये case-sensetive है |

Syntax for strcmp()

strcmp(string1, string2);

string1 -ये वो String है जिसके साथ String2 को Compare किया जाता है |
string2 - ये वो String है जिसके साथ String1 को Compare किया जाता है |
अगर दोनों string एक जैसे होते है तो ये '0' return करता है |अगर दोनों string अलग-अलग होते है तो '1' या '-1' return करता है |

strcmpi() - String Function

दो String को Compare किया जाता है | ये case-sensetive नहीं है |

Syntax for strcmpi()

strcmpi(string1, string2);

string1 - ये वो String है जिसके साथ String2 को Compare किया जाता है |
string2 - ये वो String है जिसके साथ String1 को Compare किया जाता है |
अगर दोनों string एक जैसे होते है तो ये '0' return करता है |अगर दोनों string अलग-अलग होते है तो '1' या '-1' return करता है |

strcpy() - String Function

दो String को Compare किया जाता है | ये case-sensetive नहीं है |

Syntax for strcpy()

strcpy(destination_string, source_string);

destination_string - ये वो parameter है जिसपर source के string की value copy की जाती है | अगर destination string पर कोई value भी हो तो वो overwrite हो जाती है |
source_string - ये वो parameter है जिसकी value destination पर copy की जाती है |

strdup() - String Function

String का duplicate बनाता है |

Syntax for strdup()

strdup(string);

string - ये String है जिसका duplicate बनाया जाता है |


strlen() - String Function

String की Length निकाली जाती है |

Syntax for strlen()

strlen(string);

string - ये एक normal string है, जिसकी length निकली जाती है |
strlen से निकला हुआ output integer value ही होती है ,ये किसी दूसरे integer variable में भी store करके रख सकते है |

strlwr() - String Function

Uppercase के Characters को Lowercase में convert किया जाता है |

Syntax for strlwr()

strlwr(string);

string - ये वो string है जिसको lowercase में convert किया जाता है |

strncat() - String Function

दिए हुए number के जितने character है उनसे String को जोड़ा जाता है |

Syntax for strncat()

strncat(destination_string, source_string, size_t num);

destination_string - ये वो string जिसके साथ source string को जोड़ा जाता है |
source_string - ये वो string जिसके साथ destination string को बाद में जोड़ा जाता है |
size_t num - यहाँ पर जो integer value दी जाती है उतने character वो source string से लेता है |

strncpy() - String Function

दिए हुए number के जितने character एक string से दूसरे string में copy किया जाता है |

Syntax for strncpy()

strncpy(destination_string, source_string, size_t num);

destination_string - ये वो parameter है जिसपर source के string की value copy की जाती है | अगर destination string पर कोई value भी हो तो वो overwrite हो जाती है |
source_string - ये वो parameter है जिसकी value destination पर copy की जाती है |
size_t num - यहाँ पर जो integer value दी जाती है उतने character वो destination string से लेकर source string पर copy कर देता है |

strnset() - String Function

दिए हुए number और दिए हुए character के हिसाब से string को replace करता है |

Syntax for strnset()

strnset(string, char ch, int c);

destination_string - ये एक normal string है |
char ch - ये वो character है जिससे string के हर character को replace किया जाता है |
int c - यहाँ पर जितना number है उतने character string से replace किया जाते है |

strrchr() - String Function

दिए हुए string से एक character का आखिरी occurrence के आगे का string pointer को return करता है |

Syntax for strrchr()

strrchr(string, int character);

string - ये एक normal string है |
int character - ये वो character है जिसका आखिरी occurrence के आगे का string pointer को return किया जाता है |


strrev() - String Function

String को उलटी दिशा से print करता है |

Syntax for strrev()

strrev(string);

string - ये एक normal string है |

strrstr() - String Function

दिए हुए String का आखिरी string occurrence के आगे का string pointer को return करता है |

Syntax for strrstr()

strrstr(string1, string2);

string1 - ये एक normal string है |
string2 - string1 में से ये string find करके उसका आखिरी occurrence pointer को return करता है |

strset() - String Function

दिए हुए String का आखिरी string occurrence के आगे का string pointer को return करता है |

Syntax for strset()

strset(string, int character);

string - ये एक normal string है |
int character - ये एक-एक character करके सभी characters को replace कर देता है |

strstr() - String Function

दिए हुए String का आखिरी string occurrence के आगे का string pointer को return करता है |

Syntax for strstr()

strstr(string1, string2);

string - ये एक normal string है |
int character - string1 में से ये string find करके उसका पहला occurrence pointer को return करता है |

strupr() - String Function

Lowercase के Characters को Uppercase में convert किया जाता है |

Syntax for strupr()

strupr(string);

string - ये वो string है जिसको Uppercase में convert किया जाता है |

Array in C Language

Array एक non-primitive तथा linear डेटा स्ट्रक्चर है जो कि एकसमान(similar) डेटा items का समूह होता है, अर्थात यह सिर्फ एक ही प्रकार के डेटा को ही स्टोर करेगा( या तो यह सिर्फ सभी integer डेटा को स्टोर करेगा या फिर सभी floating point को)। Array डेटा स्ट्रक्चर का प्रयोग डेटा ऑब्जेक्ट्स के समूह को संग्रहित करने के लिये किया जाता है। Array एक static डेटा स्ट्रक्चर है अर्थात् हम केवल compile time में ही मेमोरी को allocate कर सकते है और इसे run-time में बदल नही सकते |

Array के दो प्रकार के है :- 
1. Single/One Dimensional Array 
2. Two/Multi Dimensional Array 

 1. Single/One Dimensional Array 

Single/One Dimensional Array एक ऐसा Data Structure होता है, जिसमें एक ही Data Type के n Data Items एक List के रूप में Store हो सकते हैं, जबकि n Array की Size को Define करता है। यदि किसी Array की Size n हो व n का मान 10 हो तो उस Array में हम केवल दस Data Items Store करके रख सकते हैं। Array के हर Item को उसके Index Number से Access किया जाता है। किसी Array का प्रथम Item हमेंशा Index Number 0 पर Store होता है और Array का अन्तिम Item हमेंशा Index Number n-1 पर Store होता है। किसी Array के Index Number 0 को Array का Lower Bound और Index Number n-1 को Array का Upper Bound कहते हैं। 

Syntax for Single Dimensional Array Declaration :-

data_type array_name[size_of_array]; 

 for eg. int arr[5]; 

 Syntax for Single Dimensional Array Initialization :-

data_type array_name[size_of_array] = {value1, value2,...,value n}; 

for eg. int arr[5] = {1, 2, 3, 4, 5};

2. Two/Multi Dimensional Array :-

यदि किसी Array को Declare करते समय एक के बजाय दो Brackets में Array की Size को Define कर दिया जाए, तो यह एक Two Dimensional Array बन जाता है, और यदि Array की Size को दो से अधिक Brackets में दे दिया जाए तो यह Multi Dimensional Array Declare हो जाता है। जब Array को Declare किया जाता है, तब वह Memory में वहीं जाकर Store होता है, जहां उसमें Define की गई पूरी जगह उसे क्रम से प्राप्त हो जाए। जब हमें कोई Table या सारणी Memory में Store करनी होती है, तब हम Two Dimensional Array का प्रयोग करते हैं। इसमें एक Dimension Row की व दूसरी Dimension Column की होती है 

Student/SubHindiEnglishScience
Student1544675
Student2656466
Student3755655

यदि हम इसे किसी Array में Store करना चाहें तो उस Array में ये मान विभिन्न Memory Locations पर निम्नानुसार Store होंगे व इन्हे निम्नानुसार Index Numbers प्राप्त होंगे जिनसे इनकी पहचान होगी

0,00,10,2
1,01,11,2
2,02,12,2

इसमें प्रथम विधार्थी के Hindi के अंक 54 Memory Location के Index Number 0,0 पर Store होंगे। English के अंक 0,1 Location व Science के अंक 0,2 Location पर Store होंगे। इसी प्रकार दूसरे विधार्थी के Hindi के अंक Memory में 1,0 Index Number के Location पर, English के अंक 1,1 Location पर व Science के अंक 1,2 Location पर Store होंगे। 

Syntax for two Dimensional Array Declaration :-

Data_Type Array_Name [Row Size][Column Size];

Multi Dimensional Array को भी इसी प्रकार से Declare किया जा सकता हैं और उसमें Store होने वाले Elements की संख्‍या उनकी Define की गई कुल Brackets की Size के गुणनफल के बराबर होती है। माना हम एक Multi Dimensional Array निम्नानुसार Declare करते हैं: int x [2][2][3]; तो यह Statement Memory में कुल 2 X 2 X 3 = 12 Element Store कर सकेगा

Looping Statement in C Language

प्रोग्रामिंग में बहुत बार ऐसी स्थिति आती है जब कोड में किसी लाइन को या कुछ लाईन को बार बार रन कराने की आवश्यकता पड़ती है । ऐसी स्थिति में हम लूप का इस्तेमाल करते हैं । लूप भी एक तरह का प्रोग्रामिंग स्टेटमेंट है । लूप लगते समय कुछ बातें ध्यान देने की होती हैं । जैसे लूप में किन लाइन को बार बार रन करना है और कितनी बार रन करना है ।

लूप के लिए  C में  for , while और do – while  लूप इस्तेमाल किये जाते हैं ।

किसी भी लूप स्टेटमेंट के तीन भाग होते हैं और लूप काउंटर इस संख्या को निर्धारित करता है की लूप कितनी बार चलेगा । पहले भाग में हम लूप काउंटर को इनिशियलाइज़ करते हैं और इसके दूसरे भाग में हम चेक करते हैं की लूप अपनी अंतिम  या लूप ख़तम करने कंडीशन   में  पहुँच गया है की नहीं  और यदि नहीं तो हम लूप काउंटर की वैल्यू को थोड़ा बढ़ा या घटा ( लूप के तीसरे पार्ट के अनुसार ) देते हैं ।

1. for Loop :-

यह सर्वाधिक प्रयोग होने वाला Loop है। इस Loop में “C” के for Key Word का प्रयोग होता है। इस Loop की विशेषता यह है, कि इसके जितने भी Statement होते हैं, उन्हे for Loop लिखने के बाद उसके नीचे मंझले कोष्‍ठक के एक Block में लिखा जाता है और ये Statements Block तभी Execute होता है, जब for Condition सत्‍य होती है।

Syntax :-
    
 for( Initial Part; Conditional Part; Step Size Part)
      {
            Statements Block;
      }

जब for Loop का Execution होता है, तो सर्वप्रथम Loop का Variable Initialize होता है और फिर Condition Check होती है। यदि Condition सत्‍य होती है, तो Program Control for Loop के Statement Block में जाता है और वहां के Statements का Execution करता है। जब For Loop Statement Block के सभी Statements का Execution कर देता है तो Block से बाहर आने से पहले Loop के Step Size Part का Execution करता है और बताई गई Size के अनुसार Variable का मान Increment या Decrements करता है। फिर वापस Condition Check करता है यदि Condition सत्‍य होती है तो वापस Statement Block में जाता है और सभी Statements का Execution करने के बाद वापस Step Size Part का Execution करता है। ये क्रम तब तक चलता रहता है जब तक कि for Loop की Condition सत्‍य रहती है। Loop का Initialization केवल एक बार ही होता है जब पहली बार Program Control For Loop में प्रवेश करता है। for Loop का Execution हमेंशा इसी क्रम में होता है।

2. while Loop :-

for Loop की तरह यह भी किसी Statement के दोहरान का काम करता है, लेकिन फिर भी यह for Loop से काफी अलग है। इस Loop में “C” के Keyword while का प्रयोग किया जाता है। while Loop में while कोष्‍ठक में केवल Condition दी जाती है।
Variable का प्रारम्भिक मान व Step Size while के कोष्‍ठक का हिस्सा नहीं होते हैं, बल्कि Variable का प्रारम्भिक मान while Loop को शुरू करने से पहले ही Declare व Initialize कर दिया जाता है और Loop की Step Size while Condition के Statement Block का हिस्सा होती है।

Syntax :-
   
Variable Declaration;
Value Initialization;

while(Condition )
{
  Statement Block;
  Step Size;
}
Statement 1;

while Statement के कोष्‍ठक के बाद कभी भी Semi Colon (;) का प्रयोग नहीं किया जाता है। हमें Loop चलाने वाले Variable को प्रारम्भिक मान देना होता है। यह काम while Loop के बाहर ही कर लिया जाता है। जब Program Control, while Loop में प्रवेश करता है तो Program Control, Condition Check करता है। यदि Condition सत्‍य होती है तो Program Control while Loop के Statement Block में प्रवेश करता है और Statement Block का Execution करता है। Execution के बाद Statement Size तय करता है, यानी Loop के Variable का मान जरूरत के अनुसार Increment या Decrement करता है। यह क्रम तब तक चलता रहता है जब तक कि while Condition असत्‍य नहीं हो जाती है। यदि Condition सत्‍य नहीं होती है तो Program Control while Loop के Statement Block में प्रवेश नहीं करता, बल्कि सीधे ही Statement 1 पर चला जाता है।

2. do-while Loop :-

यह “C” में प्रयोग होने वाला तीसरा व अन्तिम Loop है। इसमें भी अन्‍य Loop की तरह ही तीनों आधारभूत Statements की जरूरत होती है यानी Loop के Variable का प्रारम्भिक मान, अन्तिम मान व Step Size. इस Loop की विशेषता ये है कि इस में Check होने वाली Condition Loop के अंत में Check होती है। यानी जब हमें ऐसी जरूरत हो कि प्रोग्राम में Loop के Statement या Statement Block का Execution कम से कम एक बार तो करना ही हो, तब हम इस Loop का प्रयोग करते हैं।

Syntax :-
   
Variable Declaration;
Value Initialization;

do
{
  Statement Block;
  Step Size;
}while(Condition);

Statement 1;

इस Loop की शुरूआत do Keyword से होती है और Statement Block के बाद मंझला कोष्‍ठक बंद करने के बाद while Condition दी जाती है। साथ ही यही एक Loop है, जिसमें while के Condition कोष्‍ठक के बाद ; (Semi Colon ) का प्रयोग किया जाता है। do के बाद कोई भी Colon या Semi Colon प्रयोग नहीं किया जाता है। इस Loop में प्रोग्राम Control को जैसे ही do Key word मिलता है तो Program Control सीधे ही do के  Statement Block में चला जाता है और उसमें लिखे Statements को Execute कर देता है। फिर Loop चलाने वाले Variable का Step Size Increase या Decrease प्रोग्राम के अनुसार करता है। Program Control जब इस Block से बाहर आता है तब उसे while Condition प्राप्त होती है। यहां यदि Condition सत्‍य होती है तो Program Control do से वापस Statements का Execution करता है और यदि Condition असत्‍य होती है, तो Program Control Loop को वापस Iterate नहीं करता बल्कि सीधे ही Statement 1 पर चला जाता है।

Decision Making in C Language

आप अपने program में कौनसे statements को execute करना चाहते है और कौनसे statements को skip करना चाहते है ये आप खुद decide कर सकते है। इसे decision making कहते है। ज्यादातर decision making किसी condition के base पर की जाती है।
एक particular condition आने पर आप मनचाहे statements को execute कर सकते है। इसके लिए आप कुछ built in statements को यूज़ करते है। क्योंकि ये statements conditions के साथ काम करते है इसलिए इन्हें conditional statement भी कहा जाता है। और क्योंकि ये statement program में execution को control करते है इसलिए इन्हें control statements भी कहा जाता है।

1. if statement
2. if - else statement
3. Switch statement

1. if statement

if statement एक control statement है जिसका प्रयोग एक विशेष कंडीशन को test करने के लिए किया जाता है| इसमें कंडीशन केवल एक बार execute होती है जब कंडीशन सत्य होती है|

Syntax :-

if (Condition )
{
    Statement 1;
    Statement 2;
    -----------------
    Statement n;
}


2. if - else Statement :-

जब हमें दो या दो से अधिक शर्तों के आधार पर कोई निर्णय लेना होता है, या प्रोग्राम से कोई खास काम करवाना होता है, तब हम if – else Statement का प्रयोग करते हैं। यह साधाराण if Statement का विस्तृत रूप है।

Syntax :-
   
if ( Expression and Condition )
{
    Statement 1;
    Statement 2;
    -----------------
    Statement n;
}
else
{
    Statement 3;
    Statement 4;
    ------------------
    Statement m;
}

इस Syntax के अनुसार जब if Condition सत्य होगी, तो Statement 1, Statement 2, से Statement n तक का Execution होगा और यदि if Condition असत्य होगी, तो प्रोग्राम Control, if Statement Block को छोड देगा और Default रूप से else Condition की Statements का Execution हो जाएगा। इस तरह से Statement 3, Statement 4 से Statement m तक का Execution होगा।

3. Switch statement

Switch statement भी if statement की तरह ही होता है लेकिन इसमें condition check करने की बजाय case check किया जाता है। एक particular case आने पर आप जो statements execute करना चाहते है उन्हें आप case के अंदर लिखते है।
Case एक integer variable से match किया जाता है। जो case integer variable से match हो जाता है वही case execute हो जाता है।

Syntax :-

switch(expression)
{   
case value1:   
 //code to be executed;   
 break;  //optional 
case value2:   
 //code to be executed;   
 break;  //optional 
......................   
default:   //default के अंधर वह कोड लिखे जाते है। जब कोई भी case की value match नहीं होती ।
}


Printf() & Scanf() in C Language

C Language में कोई भी value input या output करने के लिए function का use करते है | input and output दोनों के लिए अलग -2 function होते है|

scanf() :-

अगर आपको कोई भी value कीबोर्ड से insert करानी होती है तो input function का use होता है | इसके लिए scanf() function का use करते है
scanf की मदद से हम कोई भी value insert करा सकते है |

#include<stdio.h>
#include<conio.h>
Void main()
{
Int  a;
scanf(“%d”,&a);
printf(“Enter value is :%d”,a);
getch();
}

इस program में scanf() function का use किया है इससे  पहले हमने a नाम का variable declare किया है और इस variable में value scanf() की मदद से input कराएँगे | और यहाँ पर (&) का उपयोग यह सूचित करने के लिए होता है कि variable नाम के एड्रेस को उसमे मान स्टोर करने के लिए ज्ञात किया जाना चाहिए |अगर character value input करनी है तो %d की जगह %c का उपयोग किया जाता | और float value के लिए %f use होता है|

printf() :-

c language में  printf() function उन सभी को print करता है जो कि (“ “) के अन्दर लिखे जाते है |

उपरोक्त program में printf(“Enter value is :%d”,a); %d का मतलब integer value print करेगा | मान लो  अगर अपने scanf() function में 9 input किया है तो इसका output  display पर कुछ इस तरह से आयेगा |

Enter value is:9

printf() function की  मदद से हम इस तरह से display करा सकते है |

%d का use integer value को print कराने के लिए और character value के लिए %c ,float के लिए %f, string के लिए %s का प्रयोग करते है|

Basic Structure of C Language Program

1. #include <stdio.h>
2. int main() 
3. {
4. printf("Hello"); 
5. return 0; 
6. }

ये Program C Programming में सबसे पहला और आसान Program है | ऊपर दिया हुआ Program छह भाग में बटा हुआ है |
  1. Preprocessor
  2. main function
  3. {
  4. printf("Hello");
  5. return 0;
  6. }
1.Preprocessor :-

 Program में सबसे पहले preprocessors/header को लिखा जाता है | ये preprocessors अलग-अलग काम के लिए विभाजित किये हुए है,
for eg. stdio.h में printf और scanf function आते है | conio.h में getch function आता है | और भी कुछ preprocessors है |

2.int main() :-

 यहाँ पर main function का return_type integer है | main function का return_type void भी लिखा जाता है पर void कोई भी value return नहीं करता | Program की शुरुआत main() function से होती है |

3.{ :-

 हर function के  statements को curly brace open होने के बाद लिखा जाता है |

4.printf("Hello"); :-

 printf() function में लिखे हुए statement को output में print किया जाता है | इस statement को दो Double Quotes (" ") के अंदर लिखा जाता है |

5.return 0; :-

 return 0 ये Program को बंद करने की अनुमति देता है | ये '0' main function को return करता है |

6.} :-

 यहाँ पर } इस curly brace से main function को close किया है |

Operators in C Language

किसी भी प्रोग्रामिंग भाषा में विभिन्न प्रकार के Results प्राप्त करने के लिए विभिन्न प्रकार के Mathematical व Logical Calculations करने पडते हैं। इन विभिन्न प्रकार के Mathematical व Logical Calculations को Perform करने के लिये कुछ Special Symbols का प्रयोग किया जाता है। ये Special Symbols कम्प्यूटर को विभिन्न प्रकार के Calculations करने के लिए निर्देशित करते हैं। विभिन्न प्रकार के Calculations को Perform करने के लिए Computer को निर्देशित करने वाले चिन्हों को Operators कहा जाता है। साथ ही Data को Refer करने वाले जिन Identifiers के साथ ये प्रक्रिया करते हैं, उन Identifiers को इन Operators का Operand कहा जाता है।

किसी भी Programming Language मे Operators दो तरह के होते हैं:-

1.Unary Operator

कुछ Operators ऐसे होते हैं, जिन्हें कोई Operation Perform करने के लिए केवल एक Operand की जरूरत होती है। ऐसे Operators, Unary Operator कहलाते हैं। जैसे Minus ( – ) एक Unary Operator है। जिस किसी भी संख्‍या के साथ ये चिन्ह लगा दिया जाता है, उस संख्‍या का मान बदल जाता है। जैसे 9 के साथ – चिन्ह लगा देने से संख्‍या -9 हो जाती है। C Language में Support किए गए Unary Operators निम्नानुसार हैं।

& Address Operator
* Indirection Operator
+ Unary Plus
– Unary Minus
~ Bit wise Operator
++ Unary Increment Operator
– Unary Decrement Operator
! Logical Operator


2.Binary Operators

जिन Operators को काम करने के लिये दो Operands की जरूरत होती है, उन्हें Binary Operators कहते हैं। जैसे 5 + 7 को जोडने के लिये Addition Operator (+) को दो Operands की जरूरत होती है, अतः Plus एक Binary Operator भी है।

C Language में विभिन्न प्रकार के Operators को उनके काम के आधार पर कई Categories में बांटा गया है। जैसे :-
    Arithmetical Operators,
    Relational Operators,
    Logical Operators,
    Turnery or Conditional Operators,
    Increment/Decrement Operators,
    Bitwise Operators,
    Special Operators


1.Arithmetical Operators

Arithmatic Operators का उपयोग मैथमैटिकल कैलकुलेशन में किया जाता है । जैसे - की जोड़ना , घटना ,गुणा ,भाग देना इत्यादि C Programming निम्नलिखित Arithmatic Oerator को Support करती है। हम यहाँ समझने के लिए दो Variable A =10, B=20 ले रहे है| इन के द्वारा हम Arithmatic Operators को समझेंगे । 

Operator Description Example
 + दो Values को  जोड़ना  A + B = 30
 − दो Values को  घटाना A − B = -10
* दो Values को  गुणा A * B = 200
/ भाग देना B / A = 2
%  Modulus Operator  सेसफल देना B % A = 0
 ++  Increment operator Original Value के मान कोएक बड़ा देना . A++ = 11
 -- Decrement operator .Original Value के मान कोएक घटा  देना A-- = 9

2.Relational Operators 


OperatorsExplaination
< (less than)एक Operand की value दूसरे Operand से कम हो तो ये true return करता है | for eg. num1=7; num2=9;
num1 < num2
> (greater than)एक Operand की value दूसरे Operand से ज्यादा हो तो ये true return करता है | for eg. num1=9; num2=7;
num1 > num2
<= (less than or equal to)एक Operand की value दूसरे Operand से कम हो या बराबर (equal) हो तो ये true return करता है | for eg. num1=4; num2=4;
num1 <= num2
(greater than or equal to)एक Operand की value दूसरे Operand से ज्यादा हो या बराबर (equal) हो तो ये true return करता है | for eg. num1=7; num2=7;
num1 >= num2
== (equal to)दो Operands जब बराबर(equal) होते है, तब ये true return करता है |
!= (not equal to)दो Operands जब एक-दूसरे से अलग होते है, तब ये true return करता है |

3.Logical Operators 


OperatorsExplaination
&& (logical &&)अगर दोनों conditions true हो तो ये true return करेगा |
for eg. (5<6) && (6>5)
|| (logical OR)अगर दोनों में से एक भी true है , तो ये true return करेगा |
for eg. (5<6) || (6>5)
! (logical not)अगर condition true हो तो ये उसे false कर देता है |
for eg. !((5<6) && (6>5))
!((5<6) || (6>5))

4.Conditional / Ternary Operator (?:)
  • Conditional Operator में तीन Expressions होते है |
  • Conditional Operator को Ternary Operator भी कहते है |
  • Conditional Operator में अगर पहला expression true होता है, तो वो दूसरा expression output में print करता है |
  • अगर Conditional Operator में पहला expression false होता है, तो वो तीसरा expression output में print करता है |
5.Increment/Decrement Operators
  • Increment Operator (++) ये variable की value 1 से बढ़ा देता है |
  • Decrement Operator (--) ये variable की value 1 से घटा देता है |
6.Assignment Operators
  1. Assignment Operator (=)
  2. Add Assignment Operator (+=)
  3. Subtract Assignment Operator (-=)
  4. Multiply Assignment Operator (*=)
  5. Divide Assignment Operator (/=)
  6. Modulus Assignment Operator (%=)
  7. Bitwise AND Assignment Operator (&=)
  8. Bitwise OR Assignment Operator (|=)
  9. Bitwise XOR Assignment Operator (^=)
  10. Left Shift Assignment Operator (<<=)
  11. Right Shift Assignment Operator (>>=)

C Language Data type

जब हम कोई भी program बनाते है तो हमें उस program को computer पर चलाने के लिए कुछ मेमोरी की आवश्यकता होती है और ये मेमोरी हम data type की मदद से ही ले पाते है / data type ही यह बताता है की यह value किस type की है /
variable को डिक्लेअर करने पर ही program के लिए मेमोरी मिलती है  और इन variable को declare करने के लिए data type की आवश्यकता पड़ती है

ये निम्नलिखित प्रकार के होते है /

1) int
2) char
3) float 
4) double
5) string

सभी c compiler int ,char , float ,double व  string नाम के पांच प्रमुख primary data type को सपोर्ट करते है/


1) integer data type -

 integer को बिना किसी fraction भाग के रूप में देखा जा सकता है जैसे कि
34 , 56 , 75 इस प्रकार की value को  integer data type कहा जाता है / अगर  34.55 हो तो ये  integer नहीं है integer data type मेमोरी में 2 byte जगह लेते है /
example:- int number;
इस तरह से एक integer data type को डिक्लेअर किया जाता है / जहाँ पर int एक data type है और number उसका नाम है ;


2) character data type-

 
 एक सिंगल character c में कीवर्ड char द्वारा परिभाषित किया जाता है / यह केवल एक सिंगल character के लिए उपयोग किया जाता है / सामन्यतः character data type मेमोरी में 1 byte space लेता है
example:- char abc;
जहाँ char एक charecter type का data type है जिसका नाम abc  है /

3) float data type -

 यह दशमलव वाली संख्याओं के लिए प्रयोग किया जाता है जैसे कि - 34.4 इस प्रकार के number को स्टोर करने के लिए float data type का प्रयोग किया जाता है / और इस data type को floating point data type भी कहते है /
example:- float value;
 

4) double data type -

 यह float data type की तरह है अंतर ये है कि float 6 अंक के साथ 4 byte में स्टोर होती है  जबकि  double 14 अंक के साथ 8 byte का उपयोग करती है तथा float की तरह सामान data type को represents करती है
example:- double xyz;
जहाँ double एक data type है and xyz , data type का नाम है जो की कुछ भी हो सकता है
 

5) string data type -
 
 यह data type किसी नाम को represent करने के लिए उपयोग किया जाता है जैसे कि मुझे अपना नाम print कराना है तो string data type का use करना होगा /
example:- string name;


C Language Variable

किसी भी programming language में variable बहुत ही important है /
variable एक एंटिटी है जिसका एक मान होता है इसे program में एक नाम द्वारा जाना जाता है /
variable को diclare करने पर ही हमें मेमोरी मिलती है program को चलाने के लिए /
एक variable का पहला word एक alphabet होता है किसी भी variable के नाम में space नही दिया जा सकता space की जगह _ इस अंडरस्कोर का उपयोग कर सकते हो /
एक variable excecution के दौरान अलग -2 time पर अलग -2 value ले सकता है / एक variable का नाम programmer अपने हिसाब से रख सकता है /


How to diclare variable

c program में उपयोग होने वाले Variable को data type के साथ declare किया जाता है /
c language में user Variable को declare करते समय value भी दे सकते है /


Variable declare का syntax –
datatype variablename;

यहाँ पर datatype जैसे कि integer या float या char कुछ भी हो सकता है /
और उसके बाद Variable का नाम, आप Variable का नाम कुछ भी दे सकते है /


Variable के नाम लिखने के  rule

1.Variable के name की शुरुवात अल्फाबेट के words
के साथ होनी चाहिए / c language में अंडरस्कोर character (_) को एक word माना जाता है /
2.एक Variable का नाम  किसी सख्या से प्रारंभ नही हो सकता हा पर ये नंबर बाद में लिख सकते है
जैसे कि- datatype ashu3; या int ashu3;
3.कोई भी Variable का नाम keyword नहीं हो सकता है /
इस तरह हम किसी भी Variable को declare कर सकते है