Welcome to Beginners Programming.
Above the graphical representation of a program which prints “Hello World!” on the screen. Now we are going to translate the flowchart using Pascal, C and C++ programming languages.
Pascal Code | C Code | C++ Code |
|
|
|
The flowchart will serve as your blueprint, your guide developing a program. But as I have mentioned earlier, our world will be evolving within the C language. By the way, we will be using Borland C/C++ IDE, a DOS based program. If you do not have Borland C/C++ IDE you can download it from http://www.simonhuggins.com/courses/progbegin/c/download/index.htm
The Code:
#Include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
Note: C language is case sensitive meaning, capital letter N is not the same as small letter n
Dissection:
#Include | Tells the processor to treat the contents of the file stdio.h as if the contents had appeared in the source program at the point where the directive appears |
stdio.h | Which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations |
int main(void) | It is a special purpose function in C programs. When the program is then run or executed, the runtime environment will first call the main function otherwise it will be like some other function in the program. |
{ | The open curly brace indicates the beginning of the definition of the main function |
printf(“Hello World!\n”); | This line calls (executes the code for) a function named *from wikipedia |
return 0; | This line terminates the execution of the |
} | The open curly brace indicates the end of the definition of the main function |
Ok, so now are you ready to run the program? Running the program is just easy, like MSWord, the shortcut key for save is
CTRL+S (save document). In our case CTRL+F9 (execute the program)
You will notice that your program will just flicker or you will not notice it at all. “what then? Nothing happened…”, well something did happen, the IDE successfully executed your program.
“Really?”
If you want to see the output, press CTRL+F5.
Figure 2:
Output:
And you have your output. CONGRATULATIONS! You created your first program.
You can add as may printf as you want in your code. Go ahead try it.. explore…
printf(“this is a C program\n”);
printf(“Im gonna love this\n”);
printf(“its really fun\n”);
printf(“thank you very much\n”);
Well that’s it for now. I hope I have gotten your feet wet.
Next lesson in beginners programming, we will be learning how to display “hello world!” somewhere on the screen.
-End of lesson 2 Beginners Programming
No comments:
Post a Comment