After reading this C goto statement topic, you will understand its theory and examples also you will able to implement goto statement in C programming.
C goto statement is an unconditional jump statement and goto statement used to jump the program control to the specified C programming statement.
C goto statement syntax:
The syntax of goto statement is given below,
goto label;
where, the label is an identifier. When goto statement executes, the program control jumps to label which targets the specified C programming statement.
Example:
Program (1): To area of Square using goto statement.
#include<stdio.h> #include<conio.h> void main(void) { float side, area; back: printf("\n Enter the value of side of square: "); scanf("%f", &side); if(side < 0) { printf("Side of square should not be negative"); goto back; } area = side * side; printf("%f", area); getch(); }
Output (1)
Enter the value of side of square: -3 Side of square should not be negative Enter the value of side of square: 5 25.000000