Using assignment operators, we can assign value to the variables. Show Equality sign (=) is used as an assignment operator in C. Here, value 5 has assigned to the variable var. Example #include<stdio.h> int main() { int a = 10; int b = a; printf("a = %d \t b = %d\n",a,b); return 0; } Here, value of a has assigned to the variable b. Now, both a and b will hold value 10. Basically, the value of right-side operand will be assigned to the left side operand. Pictorial ExplanationCompound assignment operators
Sample ProgramExample #include<stdio.h> int main() { int a = 10, b = 5; a+=b; // same as a=a+b printf("value of a+b = %d\n",a); // a will hold the result return 0; } Topics You Might LikeHey, folks! In this article, we will be focusing on Arrow operator in C. So, let us begin! Working of Arrow operator in C?In C, this operator enables the programmer to access the data elements of a Structure or a Union. This operator Let us now focus on the structure of Arrow operator in C. Syntax of Arrow operator(->)Have a look at the below syntax!
The operator is used along with a pointer variable. That is, it stores the value at the location(variable) to which the pointer/object points. Let us now implement this operator through some examples in the upcoming section. Examples of Arrow operator (->)In the below example, we have created a Structure ‘Movie_info’. Further, we have assigned a pointer object to the structure and allocated memory to it in a dynamic manner using the C malloc() function. Arrow operator to access the data member of a C Structure
We have accessed the values of the data members using arrow operator(->). Output:
Let us now try to access the data members of Union using arrow operator. Arrow operator to access the data members of Union in C
Like Structure, we have created a Union ‘Movie_info’ and have accessd the data values using the arrow operator as shown above. Output:
ConclusionBy this, we have come to the end of this topic so feel free to comment below, in case you come across any question. References
What does << mean in C?<< is the left shift operator. It is shifting the number 1 to the left 0 bits, which is equivalent to the number 1 .
What is the symbol in C?Master C and Embedded C Programming- Learn as you go. What are the 45 operators in C?C Operators. Arithmetic Operators.. Relational Operators.. Shift Operators.. Logical Operators.. Bitwise Operators.. Ternary or Conditional Operators.. Assignment Operator.. Misc Operator.. What is && operator in C?The && (logical AND) operator indicates whether both operands are true. If both operands have nonzero values, the result has the value 1 . Otherwise, the result has the value 0 . The type of the result is int . Both operands must have an arithmetic or pointer type.
|