আপনাকে স্বাগতম আমাদের টিটোরিয়াল সাইটে আসার জন্য। আজ আমরা আপনাকে শেখাবো অপারেটর কি।
প্রোগ্রামিং শিখতে হলে আপনাকে ইংরেজীও শিখতে হবে কারণ আপনাকে কম্পিউটারকে ইংরেজীর মাধ্যমে ইনপুট দিতে হবে তাই আমার এই টিউটোরিয়ালে আমি বাংলার পাশাপাশি দরকারি কিছু যায়গায় ইংরেজী শব্দ ব্যভার করেছি।
অপারেটর হলো একটি গাণিতিক লজিক যা আপনার প্রোগ্রামকে বিভিন্ন দিক নির্দেশ দেবে। এটি সি প্রোগ্রামে সীমাবদ্ধ থাকে। নিচের নাম গুলো আপনাকে ইংরেজীতেই জানতে হবে। অপারেটর বিভিন্ন রকমের হয়ে থাকে তা হলোঃ
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Misc Operators
এই টিউটোরিয়ালট এ পাটিগণিত, রিলেশনাল, লজিক্যাল, নিয়োগ এবং অন্যান্য অপারেটরদের একের পর এক ব্যাখ্যা করবে।
Arithmetic Operators
নিচের টেবিলের সব Arithmetic Operators সি প্রোগ্রামকে সমর্থন করে। মনে করুন পরিবর্তনশীল A 10 পরিবর্তনশীল B 20:
Operator | Description | Example |
== | Checks if the values of two operands are equal or not, if yes then condition becomes true. | (A == B) is not true. |
!= | Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. | (A != B) is true. |
> | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (A > B) is not true. |
< | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (A < B) is true. |
>= | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (A >= B) is not true. |
<= | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (A <= B) is true. |
Relational Operators
নিচের টেবিলের সব Relational Operators সি প্রোগ্রামকে সমর্থন করে। মনে করুন পরিবর্তনশীল A 10 পরিবর্তনশীল B 20:
Operator | Description | Example |
== | Checks if the values of two operands are equal or not, if yes then condition becomes true. | (A == B) is not true. |
!= | Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. | (A != B) is true. |
> | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (A > B) is not true. |
< | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (A < B) is true. |
>= | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (A >= B) is not true. |
<= | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (A <= B) is true. |
Logical Operators
নিচের টেবিলের সব Logical Operators সি প্রোগ্রামকে সমর্থন করে। মনে করুন পরিবর্তনশীল A 10 পরিবর্তনশীল B 20:
Operator | Description | Example |
&& | Called Logical AND operator. If both the operands are non-zero, then condition becomes true. | (A && B) is false. |
|| | Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true. | (A || B) is true. |
! | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | !(A && B) is true. |
Bitwise Operators
Bitwise অপারেটর বিট উপর কাজ করে এবং বিট-দ্বারা-বিট অপারেশন সম্পাদন করে:
p | Q | p & q | p | q | p ^ q |
0 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
1 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 1 | 1 |
অনুমান কর যদি A = 60; এবং B = 13; নিম্নরূপ এখন বাইনারি বিন্যাসে তারা হবে:
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
সি ভাষা দ্বারা সমর্থিত Bitwise অপারেটরদের নিম্নলিখিত টেবিলে তালিকাভুক্ত করা হয়. পরিবর্তনশীল একটি 60 ঝুলিতে এবং পরিবর্তনশীল বি, তারপর 13 ঝুলিতে অনুমান:
Operator | Description | Example |
& | Binary AND Operator copies a bit to the result if it exists in both operands. | (A & B) will give 12, which is 0000 1100 |
| | Binary OR Operator copies a bit if it exists in either operand. | (A | B) will give 61, which is 0011 1101 |
^ | Binary XOR Operator copies the bit if it is set in one operand but not both. | (A ^ B) will give 49, which is 0011 0001 |
~ | Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. | (~A ) will give -61, which is 1100 0011 in 2's complement form. |
<< | Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. | A << 2 will give 240 which is 1111 0000 |
>> | Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. | A >> 2 will give 15 which is 0000 |
Assignment Operators
সি ভাষা দ্বারা সমর্থিত নিম্নলিখিত Assignment অপারেটর আছে:
Operator | Description | Example |
= | Simple assignment operator, Assigns values from right side operands to left side operand | C = A + B will assign value of A + B into C |
+= | Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand | C += A is equivalent to C = C + A |
-= | Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand | C -= A is equivalent to C = C - A |
*= | Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand | C *= A is equivalent to C = C * A |
/= | Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand | C /= A is equivalent to C = C / A |
%= | Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand | C %= A is equivalent to C = C % A |
<<= | Left shift AND assignment operator | C <<= 2 is same as C = C << 2 |
>>= | Right shift AND assignment operator | C >>= 2 is same as C = C >> 2 |
&= | Bitwise AND assignment operator | C &= 2 is same as C = C & 2 |
^= | bitwise exclusive OR and assignment operator | C ^= 2 is same as C = C ^ 2 |
|= | bitwise inclusive OR and assignment operator | C |= 2 is same as C = C | 2 |
Misc Operators ↦ sizeof & ternary
Sizeof এবং সহ কয়েক অন্যান্য গুরুত্বপূর্ণ অপারেটর আছে যা সি ভাষা দ্বারা সমর্থিত.
Operator | Description | Example |
sizeof() | Returns the size of an variable. | sizeof(a), where a is integer, will return 4. |
& | Returns the address of an variable. | &a; will give actual address of the variable. |
* | Pointer to a variable. | *a; will pointer to a variable. |
? : | Conditional Expression | If Condition is true ? Then value X : Otherwise value Y |
Operators Precedence in C
অপারেটর প্রাধান্য একটি অভিব্যক্তি পদ গ্রুপ নির্ধারণ করে. এই একটি অভিব্যক্তি মূল্যায়ন করা হয় কিভাবে প্রভাবিত করে. নির্দিষ্ট অপারেটরের অন্যদের তুলনায় বেশি প্রাধান্য আছে; উদাহরণস্বরূপ, গুণ অপারেটর ছাড়াও অপারেটর বেশী প্রাধান্য আছে.
উদাহরণস্বরূপ X = 7 + + 3 * 2; এখানে, এক্স, 13 নির্ধারিত হয় না 20 অপারেটর * + + চেয়ে বেশী প্রাধান্য আছে, তাই এটা প্রথম 3 * 2 দিয়ে গুন করা হয় এবং তারপর 7 মধ্যে যোগ করা হয়.
এখানে, সর্বোচ্চ প্রাধান্য দিয়ে অপারেটরদের টেবিলের শীর্ষে প্রদর্শিত হবে, সর্বনিম্ন সঙ্গে যারা নীচের অংশে প্রদর্শিত হবে. একটি অভিব্যক্তি মধ্যে বেশি প্রাধান্য, অপারেটর প্রথম মূল্যায়ন করা হবে.
Category | Operator | Associativity |
Postfix | () [] -> . ++ - - | Left to right |
Unary | + - ! ~ ++ - - (type)* & sizeof | Right to left |
Multiplicative | * / % | Left to right |
Additive | + - | Left to right |
Shift | << >> | Left to right |
Relational | < <= > >= | Left to right |
Equality | == != | Left to right |
Bitwise AND | & | Left to right |
Bitwise XOR | ^ | Left to right |
Bitwise OR | | | Left to right |
Logical AND | && | Left to right |
Logical OR | || | Left to right |
Conditional | ?: | Right to left |
Assignment | = += -= *= /= %=>>= <<= &= ^= |= | Right to left |
Comma | , | Left to right |