C language gives a facility to define some labels/markers and one keyword called goto to jump to those labels. Syntax for label and goto statement.

goto <Label name>;

<Label name>:
Name of a label can be defined with the same rule as of a variable name.
int validate_roll(int roll)
{
  if (roll <= 0) {
    goto not_positive_roll;
  } else if (roll > MAX_ROLL) {
    goto out_of_range_roll;
  } else {
    retun 0;
  }

  not_positive_roll:
  printf ("Please give a non-zero positive number.");
  return -1;
  out_of_range_roll:
  printf ("Please roll no. is too large.");
  return -1;

}

About our authors: Team EQA

You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.

#