I have an array which holds a structure like:
struct Point
{
int x;
int y;
}
Point array_of_structure[10] ;
for(int i=0;i<10;i++)
{
array_of_structure[i].x = i*2;
}
I want to get the structure which holds x value of 6. In this way I access the y value of that structure. How can I do it? It's something like the below:
Point p = Get the structure which contains x value of 6;
int c = p.y;
Here is a sample solution. But I need a better idea or ideas.
for(int i=0;i<10;i++)
if(array_of_structure[i].x==6)
return array_of_structure[i].y;
I thought about maybe pointers make this job but I'm not sure about it. I cannot figure out how to solve this problem.