What is the purpose of the `goto` statement in C?

What is the purpose of the goto statement in C?

a) To jump to a labeled statement
b) To exit a loop
c) To declare a variable
d) To perform a switch case

Answer:

a) To jump to a labeled statement

Explanation:

The goto statement in C is used to transfer control to a labeled statement within the same function. The use of goto can make the control flow difficult to follow, and it is generally discouraged in favor of more structured control statements like loops and conditionals.

However, goto can be useful in specific situations, such as breaking out of deeply nested loops or handling complex error checking where other control structures would be more cumbersome.

Reference links:

https://www.rameshfadatare.com/learn-c-programming/

Leave a Comment

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

Scroll to Top