In c# all arrays have a(n) ________ that equals the number of elements in the array.

Hey, folks! In this article, we will be focusing on Arrow operator in C. C language comprises of various operators to deal and manipulate the data records. One such operator is the Arrow operator.

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(->) is built using a minus(-) operator and a greater than(>) relational operator. Moreover, it helps us access the members of the struct or union that a pointer variable refers to.

Let us now focus on the structure of Arrow operator in C.


Syntax of Arrow operator(->)

Have a look at the below syntax!

(pointer variable)->(variable) = value;

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

#include 
 
struct Movie_info
{ 
    char *name; 
    char *ACC; 
};
 
int main()
{
     struct Movie_info* M;
     M = (struct Movie_info*) 
        malloc(sizeof(struct Movie_info)); 
     
     M->name = "Python with JournalDev";
     M->ACC="A";
 
     printf("Movie Information:");
     printf("\nName: %s", M->name);
     printf("\nACC: %s", M->ACC);
     return 0;
}

We have accessed the values of the data members using arrow operator(->).

Output:

Movie Information:
Name: Python with JournalDev
ACC: A

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

#include 
 
union Movie_info
{ 
    int id;
    float net_val;
};
 
int main()
{
     union Movie_info* M;
     M = (union Movie_info*) 
        malloc(sizeof(union Movie_info)); 
     printf("Movie Information:\n");
     M->id = 01;
     printf("\n ID: %d", M->id);
     M->net_val = 125.45;
     printf("\n NET VALUE: %.1f", M->net_val);
     return 0;
}

Like Structure, we have created a Union ‘Movie_info’ and have accessd the data values using the arrow operator as shown above.

Output:

Movie Information:
ID: 1
NET VALUE: 125.4

Conclusion

By this, we have come to the end of this topic so feel free to comment below, in case you come across any question.


References

  • Arrow operator in C – StackOverFlow

next → ← prev

An operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise, etc.

There are following types of operators to perform different types of operations in C language.

  • Arithmetic Operators
  • Relational Operators
  • Shift Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary or Conditional Operators
  • Assignment Operator
  • Misc Operator

Precedence of Operators in C

The precedence of operator species that which operator will be evaluated first and next. The associativity specifies the operator direction to be evaluated; it may be left to right or right to left.

Let's understand the precedence by the example given below:

The value variable will contain 210 because * (multiplicative operator) is evaluated before + (additive operator).

The precedence and associativity of C operators is given below:

CategoryOperatorAssociativity
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

Next TopicComments in C

← prev next →


In c# all arrays have a(n) ________ that equals the number of elements in the array.
For Videos Join Our Youtube Channel: Join Now


Feedback

  • Send your Feedback to [email protected]

Help Others, Please Share

In c# all arrays have a(n) ________ that equals the number of elements in the array.
In c# all arrays have a(n) ________ that equals the number of elements in the array.
In c# all arrays have a(n) ________ that equals the number of elements in the array.





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 && 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 .