Sunday, July 14, 2013

What is spaghetti code

A code with more number of goto statements in C is called as spaghetti code. A spaghetti code is that which is unstructured, twisted and tingled. If we use more number of gotos, then the code is called as Spaghetti code.



It is not good to use much of gotos because:

  • We don't need to do that. Because In C, we have many of the control structures which are better than goto statements.
  • It is risky to use. We find that goto is a good solution to use. But it is highly risky to use such a statement as it doesn't have any controlled flow.
The major issue in using a goto statement is that, it doesn't keep track of the previous records before moving on to some code. When program execution branches with a goto statement, no record is kept of where the execution came from, so execution can weave through the program willy nilly.