goto Keyword In C Programming Language


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


[youtube https://www.youtube.com/watch?v=FglRha0EdvQ]

YouTube Link: https://www.youtube.com/watch?v=FglRha0EdvQ [Watch the Video In Full Screen.]

Source Code: 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

Working of goto Statement in C Programming Language

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

Leave a Reply

Your email address will not be published. Required fields are marked *