why he put this symble ( p-> ) before each variable?
what is it means

p->fx[0] = (-p->x[0]*p->x[0]+p->x[1]); //-x1*x1+x2
  /*function 2*/
  p->fx[1] = (p->x[0]/(double)2.0 + p->x[1] + 1);

 for (i=0; i<NumFun; i++) 
   if (MINMAX[i]==0)    //minimiza
     p->fx[i]=-1*p->fx[i];
 evaluaciones++;
}


/*Put here the contraints*/
void restricciones(individuo *p)
{
 p->factible=1; 
 //first constraint
 p->g[0] = p->x[0]/(double)6.0 + p->x[1] - 13.0/(double)2.0;
 if (p->g[0] > 0)
   p->factible = 0;
  //second constraint
 p->g[1] = p->x[0]/(double)2.0 + p->x[1] - 15.0/(double)2.0;
 if (p->g[1] > 0)
   p->factible=0;

//third constraint 
 p->g[2] = 5*p->x[0] + p->x[1] - 30;
 if (p->g[2] > 0)
   p->factible=0;
}


void pobInicial()
{int j,i;
 individuo *nuevo, *p;
 for(j=0; j<POB; j++){
	nuevo = (individuo *) malloc(sizeof(individuo));
	llenaDatos(nuevo);	//llenar alos individuos
	nuevo->next = NULL;
	if(j==0)
		inicio=nuevo;
	else
		p->next=nuevo;
	p=nuevo;
 }
}


void llenaDatos(individuo *p)
{ int i,j;
  for(i=0; i< longitud; i++){
	if(flip(0.5))
		p->cromo[i]=0;
	else
		p->cromo[i]=1;
  }
}

-> is called the arrow operator and is often used to access the data members of a structure (via a pointer).
Consider a structure which looks like this:

struct dog
{
  string name;
  int age;
};

Using that structure, someone could write code like this:

dog mydog;
mydog.name = "Lady";
mydog.age = 7;

However, when for example you have a pointer to a structure, you'll have to access the elements in a different way: first you need to dereference the pointer, and then you can access the elements of that particular structure.
An example:

dog mydog;
dog *p;
p = &mydog;

(*p).name = "Lady";
(*p).age = 7;

Parentheses are needed here because the dot operator has a higher precedence than the * operator.
However, there's another way to write that code:

dog mydog;
dog *p;
p = &mydog;

p->name = "Lady";
p->age = 7;

In the above example, p is still a pointer to a dog structure, but now we access the data members of mydog using the -> (arrow) operator.
To resume: both (*p).name = "Lady" and p->name = "Lady" will do exactly the same thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.