+ 1
What does this operator " -> " means in c?
I want to know where is this operator is used and how it is used
4 Respostas
+ 3
#include <stdio.h>
struct Number{
int x, y;
};
int main() {
struct Number n1 = {4,5};
struct Number* ptr = &n1;
printf("%d",ptr->x + ptr->y);
return 0;
}
The structure just contains two variables. In the main method an instance of it is created which is n1. Then we have created a pointer of structure type and assigned it to the address of n1. So now ptr is pointing to the structure n1 and by using -> this operator we can access the values of x and y of n1. And by the way you try to predict the output.
+ 2
you should start challenging, i remeber exactly this question i had to answer frequently: p->a equals (*p).a where p is pointer and a is usually a member of class/sfructure
+ 1
Thank You Very Much I have not yet completed c and c++ so i didnt knew that but i wanted to know that because i am studying for exam Thanks alot
+ 1
Rahul Nagpure your welcome