CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Flow of control in a C program

A program's control flow describes how sequences of statements are executed.
Flow control in a C program is very similar to most other imperative and object-oriented languages.

  • C programs commence their execution at their main() function, execute their statements, and exit (return the flow of control) to the operating system.

  • It's fairly obvious that statements need to be executed in a well-defined order, as we expect programs to always behave the same way (unless some random data directs the execution path, as in computer games, simulations, and heuristic algorithms).

  • Default flow of control executes each statement in order, top-to-bottom.

  • Programs that only execute from top-to-bottom are pretty boring, and we need to control their flow with a variety of conditional statements, loops, and function-calls.

 


CITS2002 Systems Programming, Lecture 2, p8, 24th July 2024.