Step 4Editing Code, 'Hello, World!' and Compiling From the IDE
The code is something that can be best examined line by line, I think, but skipping the comment block. The first line is the '#include <stdio.h>', which is a preprocessor statement. It adds the file stdio.h to our code. The files with the extension '.h' are more correctly called header files. They contain calls to functions in C libraries that come as a part of the ANSI specification or because the owner has added functions by buying, downloading or writing more functions. C can write functions to extend itself, a very nice feature you might say.
The next line is the beginning of the main function definition. A function can have a definition or a declaration. For now, a definition is what we have, for a function named main. We can tell that it is a definition because it defines the behavior of the function within braces following immediately after. Also, a declaration ends with only a semi-colon after it, no braces.
The first line after the opening brace is the puts function being used to output text to the screen. The function declaration for this function is in the file stdio.h, included by the preprocessor. It is an ANSI standard function and is included in the ANSI libraries packaged with most ( well, yeah, virtually all these days ) compilers. It can take characters in a few different ways, but here it is using a character literal. We get to that later, too.
The next line, 'system("PAUSE")' is another function, from stdlib.h this time. It passes a command string to the opearating system for processing. The 'PAUSE' under Window's DOSbox environment or DOS will simply hold the screen, stop execution after prompting the infamous "Hit Any Key to Continue..." and wait for a response. This *IS NOT* good programming practice in most cases. In the case of Windows and MinGW compiler, this will keep you from taking more complex measures to see the output of the program as we execute it. It will not "blow up" your code here, it just isn't necessarily available in other operating systems, and therefore isn't considered good, portable code.
The last line, 'return 0;', is the code that returns a value to the operating system from main when it exits the program. In this case, 0 is a sort of dummy argument to it. When C was young, the returned value here let DOS and a few other operating systems "know" when something went amiss with the program. It acts as a signal to the OS that it needs to make some checks to certain things before resuming the control of resources the program no longer needs.
Be sure that the source file you've got in your project is identical to mine. You may skip the comment block or shorten it if you want and the double spacing is only for readability. Everything else, semi-colons included, is important. At this time, open the Execute menu and select the Compile option. This should open a dialog window that will show a progress bar at the bottom. When the progress bar is done, it should show 0 warnings and 0 errors at the positions just above the progress bar. When you get this done, you can move to the last page.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|






























