In this video tutorial lets learn how goto keyword works and its syntax in C Programming Language.
Note: As for as possible lets avoid using goto keyword and lets write programs using for loop, while loop, do while loop, continue and break statements itself. Lets learn usage of goto keyword just for the sake of knowing about it.
Related Read:
Continue Statement In C Programming Language
break Statement In C Programming Language
Video Tutorial: goto Keyword In C Programming Language
#include<stdio.h> int main() { int count = 1; while(count <= 10) { if(count == 6) goto six; // six is the label printf("%d IBM\n", count++); } six: printf("This is sixth loop\n"); return 0; }
Output
1 IBM
2 IBM
3 IBM
4 IBM
5 IBM
This is sixth loop
goto statement should always have a label associated with it. In above program label is six. Once count value is 6, control encounters goto six; Control searches for label six inside the program. Once it gets the label six, it executes the statements associated with label six.
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert