.OnlineGuruji

.OnlineGuruji

Provides E-Notes,Video Tutorials And Download Links For Students In hindi

*********************************************************

*********************************************************
********************************************************************************

Breaking

Ramchandicollege Saraipali

Technology Jobs

OnlineGuru Blog मे आपका स्वागत है ब्लॉग से संबन्धित जानकारी के लिए संपर्क करें मो ॰ नम ।-9826026747(सपन कुमार दास) अपने विषय से संबन्धित अपडेट प्राप्त करने के लिए ब्लॉग पे दिये गए Bell Icon को press करें कम्प्युटर,Science,English Grammer से संबन्धित विषय की अधिक जानकारी के लिए हमारे ब्लॉग अथवा यू ट्यूब चैनल को सब्क्राइब करे ..

Sunday, February 28, 2021

February 28, 2021

Pointer In C Language: By Sapan Das

 Pointer C लैड्ग्वेज का एक महत्वपूर्ण feature है | यह c लैड्ग्वेज का एक एसा वारियाबले है जिसमे डाटा एक्सैस वैल्यू से ना होकर उसके लोकेशन से होता है pointer variable को हम value at address के नाम से भी जानते है |

इस variable के लिए * सिम्बल का उपयोग किया जाता है |

C भाषा में pointer एक variable होता है जो दूसरे वेरिएबल के address को स्टोर करता है। यह variable प्रकार int, char, array, function या किसी अन्य पॉइंटर का हो सकता है।

POinter के द्वारा हम डाटा को variable के address की सहायता से manipulate करते है | pointer variable किसी डाटा आइटम जैसे variable या array elements के location number या address को hold करके रखता है |pointer एक एसी पावर फूल taknic है जिसके द्वारा हम data को indirect access कर सकते है क्यूंकी यह किसी variable की memory मे स्थापित रहता है |

Example :--- int x =222;

यहा पर x एक variable है जिसकी value 222 है और यह मेमोरी मे मान लीजिये 4000 लोकेशन नंबर  पर है तो हम 222 को variable के नाम से भी एक्सैस कर सकते है और location number 4000 मे स्थित वैल्यू से भी एक्सैस कर सकते है 

Declaration of Pointer variable :----

पोइंटर वारियाबले को * symbol के साथ डिक्लैर किया जाता है 

<data_type> *  <var_name >;

int * ptr ;

किसी पोइंटर वारियाबले को डाइरैक्ट initialize नहीं किया जा सकता initialize  करने के लिए & operator का उपयोग किया जाता है 

Int * ptr ;

int x=105;

ptr=&x ;










ऊपर दिये गए उदाहरण मे ptr एक integer type pointer variable है और x एक integer type simple variable है जिसमे x का एड्रैस 4000 है तथा ptr का address 2050 है line ptr=&x; x के address को pointer variable ptr मे hold करता है अर्थात ptr का मान 4000 होगा 

Address Of (&) Operator in hindi

ऑपरेटर & का उपयोग एक variable का address देता है। लेकिन, हमें varible का address प्रदर्शित करने के लिए %u का उपयोग करने की आवश्यकता है।

  1. #include<stdio.h>  
  2.  main()
  3. {  
  4. int number=50;   
  5. printf(“value of number is %d, address of number is %u”,number,&number);    
  6. }    

Output

value of number is 50, address of number is fff4

Use of Pointer:-----

1.array और data tables को manage करने के लिए pointer अधिक सक्षम है |

2। pointer का उपयोग हम function मे argumen के रूप मे कर सकते  है 

3। pointer programe के execution speed को बढ़ाता है और complexcity कोप कम करता है 

4। dynamic memory allocation मे pointer का upyog किया जाता है 

#include<stdio.h>

#include<conio.h>

void main()

{

int v=5;

int *pv;

pv=&v;

clrscr();

printf("%u\n",&v);

printf("%u\n",pv);

printf("%u\n",&pv);

printf("%d\n",v);

printf("%d\n",*pv);

printf("%d\n",*(&v));

getch();

}

65524

65524

65522

5

5

5

Pointer Arithmatic:-----

अन्य vaviable कितरह pointer variable मे भी भिन्न भिन्न arithmatic ऑपरेशन किए जा सकते है |pointer के साथ निम्न arithmatic operations होते है 

1। Addition ऑफ two pointer variable 

2। multiplication ऑफ आ pointer variable with a constant 

3। division ऑफ pointer with constant 

example :- int * mptr ;

उपरोक्त उदाहरण मे mptr एक pointer type variable है मान लेते है की इसका एड्रैस मेमोरी मे 23454 है यदि इसके मान को एक बढ़ाना चाहें तो इस पर निम्न task perform करेंगे 

mptr++ या ++mptr 

mptr=mptr+1

अब पोइंटर मेमोरी मे एड्रैस 23454 के साथ अगली स्टीठी मे जाना चाहेगा 

  c लैड्ग्वेज मे अगली स्थिति पर पोइंटर को ले जाने के लिए int type के size को जोड़ता है जो निम्न प्रकार से कार्य करता है 

example :--

int mptr =mptr + 1*(size of data type)

23454 =23454+(1*2)

23456

void main()

{

int p=5;

float q=2.5

int *iptr;

float *fptr;

clrscr();

printf("\n The value of p=%d",p);

printf("\n The value of q=%f",q);

iptr=&p;

fptr=&q;

printf("\n The value of iptr=%u",iptr);

printf("\n The value of fptr=%u",fptr);

iptr++;

fptr++;

printf("\n The value of iptr=%u",iptr);

printf("\n The value of fptr=%u",fptr);

getch();

}

output:-

the value of p=5

the value of q=2.5

value of iptr==65524

value of fptr==65520

value of iptr==65526

अरे ऑफ प्वाइंटर

अरे ऑफ पॉइंट अभी एक अरे होता है जो दूसरे वेरिएबल के एड्रेस को रखता है एड्रेस जो अरे of pointer में उपस्थित रहता है वह अलग-अलग वेरिएबल के एड्रेस को होल्ड करके रखता है एक सामान्य अरे वेरिएबल में जो नियम लागू होते हैं वही सारे नियम प्वाइटर अरे अथवा अरे of pointer में भी लागू होता है 

Void main()

{

Int *a[3];

int x=20,y=30,z=40;

clrscr ()

a[0 ]=&x;

a[1 ]=&y;

a[2 ]=&z;

for (i=0;i<3;i++ )

{

printf ("%d",*(a[I]);

}

getch()

}

}

प्वाइंटर एंड अरे जैसा कि हम जानते हैं की एक अरे सिमिलर टाइप के डाटा का कलेक्शन होता है और मेमोरी में अरे के एलिमेंट कंटीन्यूअस स्टोर होते हैं जब हम किसी अरे को डिक्लेअर करते हैं तो कंपाइलर द्वारा बेस एड्रेस को एलोकेट कर कंटीन्यूअस मेमोरी एलोकेट किया जाता है और बेस एड्रेस अरे के फर्स्ट एलिमेंट का एड्रेस होता है इसके साथ ही कंपाइलर अरे की फर्स्ट एलिमेंट को कांस्टेंट वांटेड के रूप में भी डिफाइन करता है इसे हम नीचे दिए गए उदाहरण के द्वारा आसानी से समझ सकते हैं

void main ()

{

int x[3]={10,20,30};

int *pt;

clrscr ();

pt=&x;

printf("The address of 1st 2nd and 3rd elements");

printf ("%u%u%u",pt,pt+1,pt+2);

printf ("value stored in array%d%d%d",*pt,*(pt+1),*(pt+2));

getch ();

}

प्वाइंटर एंड कैरक्टर स्ट्रिंग

जैसा कि हम जानते हैं एक स्ट्रिंग कैरेक्टर अरे होता है जो अपने में ग्रुप ऑफ कैरेक्टर्स को रखता है यदि हम एक कैरेक्टर pointer को डिक्लेअर करते हैं तो यह एक स्ट्रिंग अथवा एक सिंगल कैरेक्टर को रखता है हम नीचे दिए गए उदाहरण के द्वारा ट्रैक्टर प्वाइंटर को समझ सकते हैं

void main ()

{

char name [ ]="hello";

char *s="hello";

Char *s1= ;

s1=name;

clrscr ();

printf ("String stored at name array %s\n",name);

printf ("String stored at pointer array %s\n",s);

printf ("String stored at pointer array %s\n",s1);

s1++;

printf ("String stored at pointer array %s\n",s1);

getch ();

}







Friday, February 12, 2021

February 12, 2021

Function In C Language

#include<stdio.h>

#include<conio.h>

void main()

{

void sum();

clrscr();

printf("This program calculate the sum of two number");

sum();

getch();

}

void sum()

{

int x,y,result=0;

printf("Enter the value");

scanf("%d%d",&x,&y);

result=x+y;

printf("The sum of two number =%d",result);

getch();

}

------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

#include<conio.h>

void main()

{

void sum(int,int)

int x,y;

clrscr();

printf("This program calculate the sum of two number");

printf("Enter the value");

scanf("%d%d",&x,&y);

sum(x,y);

getch();

}

void sum(int a,int b)

{

int result=0;

result=a+b;

printf("The sum of two number =%d",result);

}

-----------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

#include<conio.h>

void main()

{

int sum(int,int)

int x,y,result=0;

clrscr();

printf("This program calculate the sum of two number");

printf("Enter the value");

scanf("%d%d",&x,&y);

result=sum(x,y);

printf("The sum of two number =%d",result);

getch();

}

int sum(int a,int b)

{

int s=0;

s=a+b;

return(s);

}

Monday, January 25, 2021

January 25, 2021

Operators In C Language By:- Sapan Das

 


Operators In "C' Language:----

Operators एक symbol होते है जिनका उपयोग सी लैड्ग्वेज मे mathematical calculation और लॉजिकल डीसीजन लेने के लिए किया जाता है | इसकी सहायता से किसी variable या वैल्यू को ऑपरेट किया जाता है |उदाहरण के लिए + एक ऑपरेटर है जिसका उपयोग दो वैल्यू को जोड़ने के लिए किया जाता है |

Roperators एक या एक से अधिक वारियाबले कोंस्टंट या operands के साथ मिल कर कम करते है | सी लैड्ग्वेज मे कई बिल्ट इन operators पाये जाते है 

Types Of Operators In C

1 Arithmatic Operators:- इस operators का उपयोग बेसिक mathematical operation perform करने के लिए किया जाता है 

Symbols

Operators

Description

+

Addition

इस operators का उपयोग दो operands को जोड़ने के लिए किया जाता है

-

Substraction

इस operators का उपयोग दो operands को घटानेके लिए किया जाता है

*

Multiplication

इस operators का उपयोग दो operands को गुणा के लिए किया जाता है

/

Division

इस operators का उपयोग दो operands को भाग के लिए किया जाता है

%

Modulo Division

इस operators का उपयोग दो operands को शेष्फल के लिए किया जाता है

#include <stdio.h>

void main() {

    int num1, num2, sum, sub, mul, div, mod;

    printf("Enter the first number: ");

    scanf("%d", &num1);

    printf("Enter the second number: ");

    scanf("%d", &num2);

    // Perform arithmetic operations

    sum = num1 + num2;

    sub = num1 - num2;

    mul = num1 * num2;

    div = num1 / num2;

    mod = num1 % num2;

    // Print the results

    printf("Sum = %d\n", sum);

    printf("Difference = %d\n", sub);

    printf("Product = %d\n", mul);

    printf("Quotient = %d\n", div);

    printf("Remainder = %d\n", mod);

}

Output
Enter the first number: 100
.Enter the second number: 50
Sum = 150
Difference = 50
Product = 5000
Quotient = 2
Remainder = 0

2 Relational Operators

इस ऑपरेटर का प्रयोग प्रोग्राम मे दिये गए वैल्यू के बीच रेलतीओन चेक करने के लिए किया जाता है इसका output हमे लॉजिकल प्रपट होता है लॉजिकल मान या तो true होगा या false होगा 

Symbols

Operators

Description

> 

Greater then

इस operators का उपयोग दो operands को बीच greater चेक करने के लिए किया जाता है अगर first operands की value second operands से बड़ी है तो true वैल्यू रिटर्न करता है नहीं तो false value return करता है  

< 

Less then

इस operators का उपयोग दो operands को बीच लेस चेक करने के लिए किया जाता है अगर first operands की value second operands से छोटी है तो true वैल्यू रिटर्न करता है नहीं तो false value return करता है  

>=

Greater then equal to

इस operators का उपयोग दो operands को बीच greater और  बराबर चेक करने के लिए किया जाता है अगर first operands की value second operands से बड़ी या बराबर  है तो true वैल्यू रिटर्न करता है नहीं तो false value return करता है  

<=

Less then equal to

इस operators का उपयोग दो operands को बीच less और  बराबर चेक करने के लिए किया जाता है अगर first operands की value second operands से छोटी या बराबर  है तो true वैल्यू रिटर्न करता है नहीं तो false value return करता है  

==

equal to

इस operators का उपयोग दो operands की वैल्यू बराबर है की नहीं चेक करने के लिए किया जाता है अगर दोनों operands की वैल्यू बराबर है तो true return करेगा नहीं टी false retusn करेगा

!=

Not equal to

इस operators का उपयोग दो operands की वैल्यू बराबर नहीं  है चेक करने के लिए किया जाता है अगर दोनों operands की वैल्यू बराबर नहीं है तो true return करेगा और बराबर है तो  false retusn करेगा                               

#include <stdio.h>

void main() {
    int x, y;

    printf("Enter the value of x: ");
    scanf("%d", &x);

    printf("Enter the value of y: ");
    scanf("%d", &y);

    // Relational operators
    printf("x == y: %d\n", x == y);
    printf("x != y: %d\n", x != y);
    printf("x > y: %d\n", x > y);
    printf("x < y: %d\n", x < y);
    printf("x >= y: %d\n", x >= y);
    printf("x <= y: %d\n", x <= y);

}
output:-
Enter the value of x: 10
Enter the value of y: 20
x == y: 0
x != y: 1
x > y: 0
x < y: 1
x >= y: 0
x <= y: 1

3 Logical Operators 

 Logical Operators का उपयोग relational operator  को जोड़कर एक complex expression को बनाने के लिए किया जाता है इस ऑपरेटर को solve करने पर जो मान आता है वह हमेश लॉजिकल होता है 

Symbols

Operators

Description

&&

Logical AND

Truth Table

||

Logical OR

Truth Table

!

Logical NOT

Truth Table

उपर दिये गए table मे Logical AND और Logical OR को binary  operator   के रूप मे उपयोग करते है तथा Logical  NOT unary operator के रूप मे उपयोग करते है क्यूंकी इसमे सिर्फ एक operand की आवश्यकता पढ़ती है 

लॉजिकल operators को समझने के लिए हमे Truth Table की आवश्यकता पढ़ती है 

Truth Table

a

b

a && b

a || b

! a

! b

1

1

1

1

0

0

1

0

0

1

0

1

0

1

0

1

1

0

0

0

0

0

1

1

Example:- int a,b,c;

a=10; b=20; c=30;

(a>b) && (c<b)

10>20 && 30<20

F && F

output : F


4 Conditional operators :

इस operators को ternary operators के नाम से भी जाना जाता है इस operators  मे तीन भाग होते है जो ? और : से divide रहते है पहले भाग मे कंडिशन चेक होता है अगर दिया गया कंडिशन सही है दूसरा भाग execute होता है नहीं तो तीसरा भाग execute  होता है 

Syntax:- (condition ? expression1  : expression1  )

int a,b;

a=10;

b=20;

((a>b) ? printf("a is big number"); : printf("b is big number"); )

Example

#include <stdio.h>

void main(){

    int a, b, max;

    printf("Enter three integers: ");

    scanf("%d  %d", &a, &b);

    // Conditional operator to find the maximum of a, b, and c

    max = (a > b) ? a : b;

    printf("The maximum of %d and %d is: %d\n", a, b,max);

}

Enter three integers: 100

50

The maximum of 100 and 50 is: 100

5 Assignment Operators :--- 

इस ऑपरेटर को "=": symbol से दर्शाते है इसका उपयोग किसी variable मे value को assign करने के लिए किया जाता है जैसा की हम जानते है की किसी एक्स्प्रेश्न मे दो भाग होते है LHS और RHS और दोनों भाग के बीच हम assignment oprator का उपयोग करते है अर्थात RHS के equation को solve करने के बाद जो value output के रूप मे प्रपट होता है उसे LHS के variable मे स्टोर करने के लिए assignment oprator का उपयोग होता है arithmatic opratpr के साथ assignment oprator का उपयोग होता है 

इसे हम निम्न उदाहरण के द्वारा समझ सकते है :---

यदि int m=25 है तो 

Operators

Meaning

Example

Result

+=

m+=10

m=m+10

m=35

-=

m-=10

m=m-10

m=15

*=

M*=10

m=m*10

m=250

/=   

m/=10

m=m/10

m=2

%=

M%=10

m=m%10

m=5

#include <stdio.h>

void main() {

    int x, y;

    printf("Enter the value of x: ");

    scanf("%d", &x);

    printf("Enter the value of y: ");

    scanf("%d", &y);

    // Assignment operator (x = y)

    x = y;

    printf("The value of x after assignment: %d\n", x);

}

Enter the value of x: 30

Enter the value of y: 20

The value of x after assignment: 20

6 Increment and Decrement operators:-

यह operator c का मुख्य operator है समान्यतः दूसरे लैड्ग्वेज मे यह ऑपरेटर नहीं पाया जाता है increment operator को ++ तथा decrement operator को -- symbol से दर्शाया जाता है इन operarors का उपयोग किसी variable की value को एक one increment अथवा एक one decrement करने के लिए किया जाता है इन operarors को variable के पहले अथवा variable बाद दोनों ही स्थिति मे उपयोह किया जाता है अगर वारियाबले के पहले करते है तो prefix और यदि variable के बाद करते है तो postfix increment/decrement ऑपरेटर कहलाता है 
prefix increment/decrement  ++m /--m
postfix increment/decrement m++/m--
pre और post मे एक मुख्य अंतर होता है प्री इंक्रेमेंट मे पहले 1 को ओपेरेंड़ मे जोड़ता है और फिर आन्सर को left side के variable मे assign करता है जबकि पोस्ट इंक्रेमेंट पहले left side के variable मे assign करता है और फिर ओपेरेंड़ मे जोड़ता है

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e;
a=10;
b=a++;
printf("%d",b);
c=10;
d=++c;
printf("%d",d);
getch();
}
आउटपुट:-
10 11 

7 Bitwise Operators

Bitwise Operators in C:

Bitwise operators in C manipulate individual bits within integers. They are essential for tasks like low-level programming, cryptography, and optimization. Here's a breakdown of the available operators:

1. Bitwise AND (&):

  • Performs logical AND on corresponding bits of two operands.
  • If both bits are 1, the result is 1; otherwise, it's 0.
  • Example:

C भाषा में बिटवाइज़ ऑपरेटर

C भाषा में बिटवाइज़ ऑपरेटर एक संख्या के बिट्स पर संचालन करने के लिए उपयोग किए जाते हैं। इन ऑपरेटरों का उपयोग low-level programming, क्रिप्टोग्राफी और optimization जैसे कार्यों के लिए किया जाता है।

उपलब्ध बिटवाइज़ ऑपरेटर:

  1. बिटवाइज़ एंड (&):
    • दो ऑपरेंड के संगत बिट्स पर तार्किक AND करता है।
    • यदि दोनों बिट्स 1 हैं, तो परिणाम 1 है; अन्यथा, यह 0 है।
    • उदाहरण:

int x = 5;  // 0101

int y = 3;  // 0011

int z = x & y;  // 0001 (1)

2. Bitwise OR (|):

  • Performs logical OR on corresponding bits of two operands.
  • If at least one bit is 1, the result is 1; otherwise, it's 0.
  • Example:

2.बिटवाइज़ OR (|):

  • दो ऑपरेंड के संगत बिट्स पर तार्किक OR करता है।
  • यदि कम से कम एक बिट 1 है, तो परिणाम 1 है; अन्यथा, यह 0 है।
  • उदाहरण:

int x = 5;  // 0101

int y = 3;  // 0011

int z = x | y;  // 0111 (7)

3. Bitwise XOR (^):

  • Performs logical XOR (exclusive OR) on corresponding bits of two operands.
  • If the bits are different, the result is 1; otherwise, it's 0.
  • Example:

 

बिटवाइज़ XOR (^):

  • दो ऑपरेंड के संगत बिट्स पर तार्किक XOR (एक्सक्लूसिव OR) करता है।
  • यदि बिट्स अलग हैं, तो परिणाम 1 है; अन्यथा, यह 0 है।
  • उदाहरण:

int x = 5;  // 0101

int y = 3;  // 0011

int z = x ^ y;  // 0110 (6)

 

4. Bitwise NOT (~):

  • Inverts all bits of an operand.
  • 0 becomes 1, and 1 becomes 0.
  • Example:

बिटवाइज़ NOT (~):

  • एक ऑपरेंड के सभी बिट्स को इनवर्ट करता है।
  • 0 बन जाता है 1, और 1 बन जाता है 0
  • उदाहरण

 

int x = 5;  // 0101

int z = ~x;  // 1010 (-6)

5. Bitwise Left Shift (<<):

  • Shifts the bits of an operand to the left by a specified number of positions.
  • Zeros are filled in from the right.
  • Example

 

बिटवाइज़ लेफ्ट शिफ्ट (<<):

  • एक ऑपरेंड के बिट्स को निर्दिष्ट संख्या में स्थिति से बाईं ओर शिफ्ट करता है।
  • दाईं ओर से शून्य भरे जाते हैं।
  • उदाहरण

int x = 5;  // 0101

int z = x << 2;  // 0100 (20)

                       

6. Bitwise Right Shift (>>):

  • Shifts the bits of an operand to the right by a specified number of positions.
  • The behavior of the sign bit depends on the implementation:
    • Arithmetic shift: The sign bit is preserved.
    • Logical shift: Zeros are filled in from the left.
  • Example:

बिटवाइज़ राइट शिफ्ट (>>):

  • एक ऑपरेंड के बिट्स को निर्दिष्ट संख्या में स्थिति से दाईं ओर शिफ्ट करता है।
  • साइन बिट का व्यवहार कार्यान्वयन पर निर्भर करता है:
    • अंकगणितीय शिफ्ट: साइन बिट संरक्षित रहता है।
    • तार्किक शिफ्ट: बाईं ओर से शून्य भरे जाते हैं।
  • उदाहरण:

 

int x = -5;  // 1011

int z = x >> 2;  // 0010 (-3) (assuming arithmetic shift)

 









Example

#include <stdio.h>

void main() {

    int x = 10, y = 5;

    // Bitwise AND (&)

    int andResult = x & y;

    printf("Bitwise AND: %d\n", andResult);

    // Bitwise OR (|)

    int orResult = x | y;

    printf("Bitwise OR: %d\n", orResult);

    // Bitwise XOR (^)

    int xorResult = x ^ y;

    printf("Bitwise XOR: %d\n", xorResult);

    // Bitwise NOT (~)

    int notX = ~x;

    printf("Bitwise NOT of x: %d\n", notX);

    // Bitwise left shift (<<)

    int leftShiftResult = x << 2;

    printf("Bitwise left shift: %d\n", leftShiftResult);

    // Bitwise right shift (>>)

    int rightShiftResult = x >> 2;

    printf("Bitwise right shift: %d\n", rightShiftResult); 

}

Output

Bitwise AND: 0

Bitwise OR: 15

Bitwise XOR: 15

Bitwise NOT of x: -11

Bitwise left shift: 40

Bitwise right shift: 2

8 Special Operators 











Operator Precedence and associativity in C

सी में एक ही अभिव्यक्ति में विभिन्न प्रकार के कई ऑपरेटर हो सकते हैं। सी कंपाइलर ऑपरेटरों के प्राथमिकता और साहचर्य के आधार पर इसका मूल्य मूल्यांकन करता है। ऑपरेटरों की प्राथमिकता यह निर्धारित करती है कि अभिव्यक्ति में उनका मूल्यांकन किस क्रम में किया जाता है। उच्च प्राथमिकता वाले ऑपरेटर पहले मूल्यांकन किए जाते हैं। उदाहरण के लिए, इस अभिव्यक्ति पर एक नज़र डालें -


x=7+3*2; 
यहाँ, गुणन ऑपरेटर "*" का योग ऑपरेटर "+" की तुलना में उच्च प्राथमिकता है। इसलिए, पहले गुणन 3 * 2 किया जाता है और फिर 7 में जोड़ा जाता है, जिसके परिणामस्वरूप "x = 13" होता है।

Associativity in C

सी में ऑपरेटरों का साहचर्य एक अभिव्यक्ति के भीतर एक प्रोग्राम का मूल्यांकन की दिशा (बाएं से दाएं या दाएं से बाएं) को संदर्भित करता है। ऑपरेटर साहचर्य का उपयोग तब किया जाता है जब एक अभिव्यक्ति में समान प्राथमिकता के दो ऑपरेटर दिखाई देते हैं। निम्नलिखित उदाहरण में -(15/5)*2   3*2=6
15/5*2

दोनों "/" (विभाजन) और "*" (गुणन) ऑपरेटरों की समान प्राथमिकता होती है, इसलिए मूल्यांकन का क्रम साहचर्य द्वारा तय किया जाएगा।

तालिका के अनुसार, गुणात्मक ऑपरेटरों का साहचर्य बाएं से दाएं है। इसलिए, अभिव्यक्ति का मूल्यांकन इस प्रकार किया जाता है -

(15/5)*2  

3*2=6

 

#include <stdio.h>

Void  main()

{

   int a = 20;

   int b = 10;

   int c = 15;

   int d = 5;

   int e;

   e = (a + b) * c / d;    

   printf("e:  %d\n",  e);

      }

Output

Run the code and check its output

 

e: 90

In this expression, the addition of a and b in parenthesis is first. The result is multiplied by c and then the division by d takes place.