C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » Syntax References

Syntax of goto statement in C/C++ programming language

C/C++ programming language goto statement: what is break, when it is used and how, where t is used? Learn about goto statement with Syntax, Example.

goto is a keyword in C, C++ programming language, it is a basically jumping statement and used to transfer the program’s control anywhere (to a particular label and label can be defined anywhere within a scope) within a scope.

Here is the syntax of goto statement in C/C++:

//any scope
		goto label_name;

Here, I assumed there is a scope and we have to move program’s control from top to bottom, condition is optional here.

Consider the given example:

#include <stdio.h>

int main()
	int num;
	printf("Enter a positive integer: ");
	//if number is less than 0 then transferring the
	//program control to QUIT
		goto QUIT;
	printf("Entered number is: %d\n",num);
	QUIT: //label
	printf("BYE BYE!!!\n");
	return 0;


First run:
Enter a positive integer: 100 
Entered number is: 100

Second run:
Enter a positive integer: -10 

Consider the output on “second run”, here the input value is -10 which is less than 0, thus program’s control moved to QUIT without printing the value.

Liked this article? Do share with your friends :)