Goto Statement In C Language
The goto statement is rarely used because it makes program
confusing, less readable and complex.
When a goto statement is encountered in a C program, the
control jumps directly to the label mentioned in the goto statement.
Syntax of goto statement in C
goto label_name;
: :
: :
label_name: c statement
Fig: Goto statement in c |
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int sum=0;
for(int
i=0;i<=10;i++)
{
sum=sum+i;
if(i==5)
{
goto addition;
}
}
addition:
printf(“%d”, sum);
getch();
}
Output:
15
No comments:
Post a Comment