The goto statement in C Programming is useful to alter the flow of a program. When the compiler reaches the goto statement, then it will jump unconditionally ( both forward and backward ) to the location specified in it (we called it a label).
Unlike the Break and Continue, the goto statement in this Programming doesn’t require any If condition to perform.
C Goto Statement Syntax
The label specified after the goto statement is the location where we place the code block to execute. From the below syntax, you can understand that we can place the label anywhere in the program. It doesn’t matter if you put it before the goto or after.

Goto Statement in C Example
This program for goto allows the user to enter his/her individual subject marks. Next, it will check whether the person passes or fails using the Goto Statement.
#include <stdio.h>
int main()
{
int Totalmarks;
printf(" \n Please Enter your Subject Marks \n ");
scanf("%d", & Totalmarks);
if(Totalmarks >= 50)
{
goto Pass;
}
else
goto Fail;
Pass:
printf(" \n Congratulation! You made it\n");
Fail:
printf(" \n Better Luck Next Time\n");
return 0;
}

In the above program, Pass and Fail are the labels we used. First, we declared the integer variable Totalmarks. In the next line, the Printf function will ask the user to enter his/her total marks. The scanf function will store the user-specified value in the Totalmarks variable.
In the next line, we used an if-else statement to check whether the user entered value is greater than or equal to 50. Please refer to the Break, Continue, else if condition, and switch case articles in C Programming.
If the condition is TRUE, the C Goto statement inside the If block will take the compiler to the Pass label and execute the block of code inside the Pass label.
printf(" \n Congratulation! You made it\n");
Else (If the condition is FALSE), the code inside the Else block will take the compiler to the Fail label. Next, it executes the code block inside the Fail label.
printf(" \n Better Luck Next Time\n");
NOTE: Although all the programming languages support goto statements. However, it is always good practice to avoid using it or at least minimize its usage. Instead of using this, we can use alternatives such as Break and Continue.
C goto statement backward jump example
We can use the goto statement backward jump, to move the compiler to the forward (upper) position by calling the label. Although it looks fascinating, it is always advisable to use the while loop instead of the goto statement backward jump.
In the following example, we declared a label (menu) with a few choices. If the user chooses a choice, display the message related to the selected menu and jump to the compiler to the menu label to display the menu items in the console. It means on each entry, the goto statement jumps the compiler to a menu label and displays the list of menu items to the user to select.
TIP: If the program is large and complex, use functions from the list of available function types.
#include <stdio.h>
int main() {
int choice;
menu:
printf("\n===== MENU =====\n");
printf("1. Programming Tutorials\n");
printf("2. BI Tutorials\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice == 1) {
printf("Welcome to Programming Languages!\n");
goto menu;
}
if (choice == 2) {
printf("Welcome to BI Tutorials!\n");
goto menu;
}
if (choice == 3) {
printf("See You Soon\n");
return 0;
}
printf("Invalid choice!\n");
goto menu;
}
===== MENU =====
1. Programming Tutorials
2. BI Tutorials
3. Exit
Enter your choice: 1
Welcome to Programming Languages!
===== MENU =====
1. Programming Tutorials
2. BI Tutorials
3. Exit
Enter your choice: 2
Welcome to BI Tutorials!
===== MENU =====
1. Programming Tutorials
2. BI Tutorials
3. Exit
Enter your choice: 5
Invalid choice!
===== MENU =====
1. Programming Tutorials
2. BI Tutorials
3. Exit
Enter your choice: 3
See You Soon
Difference between the C goto statement and the break
The break statement is useful for terminating the loop and exiting the compiler from the existing loop. On the other hand, the goto statement helps jump the compiler forward or backwards to a specified label.
break statement example
In the following example, the for loop iterates from 1 to 5. When the I value reaches 3, the if statement becomes true and the break statement terminates the for loop without printing 3 (and 4, 5).
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 5; i++)
{
if (i == 3)
break;
printf("%d\n", i);
}
printf("Loop ended.");
return 0;
}
1
2
Loop ended.
C goto statement example
The program starts with printing numbers from 1, and the increment operator increments the i value by 1 within the loopstart label. Until the i value becomes 3, the goto statement performs a backward jump to the label to print the numbers. When i reach 3, the condition fails, and the compiler moves to the next line without executing the goto statement.
#include <stdio.h>
int main()
{
int i = 1;
loopstart:
printf("%d\n", i);
i++;
if (i < 3)
goto loopstart;
printf("Loop ended.");
return 0;
}
1
2
Loop ended.