Username:
Password:
Advanced C Programming Tutorials

Fundamental Concepts / Program Execution

Subtitles of the Movie

As you know, every program starts running with a function named Main. Well, almost. Some things happen before Main is called. The global variables are all set to their initial values. Well, that is the ones that you specified as having initial values are set. Then the Main function is called. There is no prototype for this function in the header files. In face, there are a couple of ways that it can be declared. It's always declared with a return type of an int and at the bottom of the function you just put in a return statement with an integer value. Another way to define the function is with two arguments. They are traditionally named argc and argv but you can call them anything you want because the names are only for use inside the main function. They contain the argument strings passed to the program from its environment. argc is a count of the number of arguments and argv is an Array of pointers to strings. There is a bit of flexibility in what they actually pass because of the capabilities of different operating systems. For example, if a system is not able to provide mixed upper and lowercase arguments, it is required that the arguments be in lowercase. No matter what, the point argv in the Array at the offset of argc is a null pointer. If the value of argc is non-zero, which means some arguments are present, the value of argv zero is the name of the program being run. The reason for this, by the way, is on the UNIX system the same program can be listed in the directory under different names. Which name you use to run it determines how it runs. For example, the text editor VI is also listed in the directory as VIEW. And when you run it that way, it loads text files in Read-only mode. If the values of Arg C are greater than one, the values of argv are string pointers pointing to program parameters passed to the program from its environment. Under normal circumstances, these are command-line arguments. You must end the main function by using a return statement or by calling the exit function. They both have the same result; that of terminating the program with a specified integer value as its exit code. I told you I would tell you some things you didn't know and here's one of them. It says in the ANSI specification that reaching the terminating brace of the main function is the same as executing return statement or calling an exit function with the integer value of zero. It's a minor point but I have encountered some C compilers that are not compliant. They complain until I put in a return statement or an exit call.

Tutorial Information

Course: Advanced C Programming
Author: Arthur Griffith
SKU: 33965
ISBN: 1-935320-24-6
Release Date: 2009-01-30
Duration: 5.5 hrs / 82 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available