Friday, September 3, 2010

Turbo C Programming Day 1a: Basic input, output and variables

Hi all. So this will be the start of a series of tutorials as a crash course for Turbo C Programming. 
As students probably know, Turbo C is one of the first programming languages taught at college.

It's interface looks primitive compared to modern IDEs such as Visual Studio, but still, Turbo C can be a powerful programming language, and a fundamental knowledge on computer programming in general begins here.



Assuming you already have Turbo C installed, let's continue. First, as shown in screenshot above, we need to set first the directories so the compiler knows where to find the files it needs.

Assuming you install your Turbo C in "C:\TC", so your directories settings should be same as above. Never forget this, as this is a common issue many newbies encounter.



Now let's begin coding. Shown above is a code listing for a very simple program for basic output, printing to screen the words "Hello World".
#include   <= this one tells the compiler to include the code listing found in the file stdio.h, which in general contains basic routines for standard input and output functions, and this includes the statement "printf".

main()  <= like in every programming language, every program must have a "main()" routine or function, which is the starting or entry point of the program. Notice that every function must be enclosed in { and }.

printf("Hello World");   <= notice that every line of code, except for comments, within a function must be ended by semicolon(;).

The statement "printf" is an example of a method, a routine that accepts a parameter in between its parentheses and does an action about it. In this case, the parameter is "Hello World", and the action is printing it on screen.

getch();  <= is simply a method or command to tell the system to wait for user keyboard input before terminating. Without this, we wouldn't be able to see "Hello World" outputted to screen as the program is immediately terminated after printing in split second.


To actually make the program run, after saving(Shortcut F2), we must compile it first by choosing the option above.


After compilation, we run the program by choosing the menu option above.


And here is our first output, hooray! We are now able to print words, sentences, or even paragraphs onto a computer screen!

P.S: Printing "Hello World" to output stream is already a programming tradition when it is your first time trying out a programming language.

If you have questions, please feel free to ask, or leave a comment. Thanks! Stay tuned!

2 comments:

  1. How can I attach a javascript on a jpeg document in turbo ..?? can you also tell me the script which can enable me to get into other computers my friend is doing it but not telling me.. shafay1996@yahoo.com

    ReplyDelete
  2. how can i download this? answer me please

    ReplyDelete