In this tutorial you are going to learn how to use effectively goto statement in C Language with the help of an example.
In C programming language goto is a special type of statement which we can use when we want to transfer the control of execution at some another label.
The goto statement required a label in order to identify the place where the branch is to be transfered.
This Label can be any valid variable name. And this Label must be followed by a colon and it is placed just before the statement where the control of goto is to be transferred.
Syntax of goto:
1
2
3
4
5 goto label;
... .. ...
... .. ...
label:
statement;
C Language goto statement example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int n; printf("Enter the no"); scanf("%d", &n); if(n<=10) goto no; else { printf("\n No. is greater than the 10"); printf("\n Enjoy the C Language."); exit(0); } no: printf("No is smaller than 10"); getch(); return 0; } |
output :

Let see the explanation of the above goto C Program.
The above Program is a basic example to clear the concept of c go to statement. In the above program, you can see that there is a variable n of integer type. Now, what the above program will do?
It will check the condition with the help of if statement. If the condition will satisfy then it will transfer the control at label no as the property of goto statement of C and logic of the above program.
Now when we will give any input less then or equal to 10 then it will satisfy the if condition. And if the condition will satisfy then if body will execute and control will transfer to the label “no”.
Now after insertion in the body it will transfer to label no as mentioned goto no.
So it will print “no is smaller than 10” as output. That is all about the goto statement in the C programming language. Basically it will used by the programmers very rarely and also this statement is not that much popular as per real world solutions.
Now I hope your concept is now cleared 🙂
Hi! I could have sworn I’ve been to this website before but after
reading through some of the post I realized it’s new to me.
Nonetheless, I’m definitely delighted I found it and I’ll be book-marking and checking back frequently!
I was suggested this web site by my cousin.
I’m not sure whether this post is written by him as
no one else know such detailed about my difficulty.
You’re wonderful! Thanks!
I got this web page from my buddy who told
me on the topic of this site and at the moment this time I am visiting this site and reading very informative content at this time.
Just wish to say your article is as surprising. The clarity in your post is simply
cool and i can assume you are an expert on this subject.
Well with your permission allow me to grab your feed to keep updated with forthcoming post.
Thanks a million and please keep up the gratifying work.
Very rapidly this web site will be famous amid all
blog visitors, due to it’s nice articles