VOOZH about

URL: https://www.geeksforgeeks.org/c/arrow-operator-in-c-c-with-examples/

⇱ Arrow operator -> in C/C++ with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Arrow operator -> in C/C++ with Examples

Last Updated : 12 Jul, 2025

An Arrow operator in C/C++ allows to access elements in Structures and Unions. It is used with a pointer variable pointing to a structure or union. The arrow operator is formed by using a minus sign, followed by the greater than symbol as shown below. 
Syntax:  

(pointer_name)->(variable_name)


Operation: The -> operator in C or C++ gives the value held by variable_name to structure or union variable pointer_name.
Difference between Dot(.) and Arrow(->) operator:  

  • The Dot(.) operator is used to normally access members of a structure or union.
  • The Arrow(->) operator exists to access the members of the structure or the unions using pointers.


Examples: 

  • Arrow operator in structure:

Output: 
18

 

Time complexity: O(1).

Auxiliary space: O(n). // n is the  size of memory that is being dynamically allocated using the malloc function to store the structure student. The amount of memory used is proportional to the size of the structure and the number

  • Arrow operator in unions:

Output: 
18

 
Comment
Article Tags: