Saturday 16 March 2013

goto error example


main()
{
    int i=1;
    while (i<=5)
    {
       printf("%d",i);
       if (i>2)
      goto here;
       i++;
    }
}
fun()
{
   here:
     printf("PP");
}
Answer:
Compiler error: Undefined label 'here' in function main
Explanation:
Labels have functions scope, in other words The scope of the labels is limited to functions . The label 'here' is available in function fun() Hence it is not visible in function main.



Blog Author: Vijay Kumar

Go to: Java Aptitude


No comments:

Post a Comment