goto statement in C
C
Language में goto स्टेटमेंट एक जम्प स्टेटमेंट है कभी-कभी इसे अनकंडीशनल स्टेटमेंट भी कहते
है। C प्रोग्राम में कही से कही भी जम्प करने के लिए goto स्टेटमेंट का प्रयोग करते है।
Youtube Video
Syntax
1 – label: . . . goto label; |
Syntax
2 - goto label; . . . label: |
//
C program to print numbers //
from 1 to 10 using goto statement #include <stdio.h> #include <conio.h> void main ( ) { int n = 1; label: printf("%d\n",n); n++; if (n <= 10) goto label; } |
//Program
to demonstrate //goto
statement in C Program #include <stdio.h> #include <conio.h> void main ( ) { int num; clrscr ( ); printf("Enter any
number"); scanf("%d",&num); if (num % 2 == 0) // jump to even goto even; else // jump to odd goto odd; even: printf("%d is even", num); // return if even getch(); return; odd: printf("%d is odd", num); getch(); } |
Disadvantages
of using goto statement:
It makes the program logic very complex.
Use of goto makes the task of analyzing and verifying the correctness of programs very difficult.
Simply avoided using break and cnontinue statements.
No comments:
Post a Comment