What is Computer Language?
How can I communicate with computer? Computer is not a human like me? Whenever I say hello to computer he does not understand and do not give me reply then what?
Relax! We use languages to communicate with each other and give sense of our idea and feelings. In the same way we use computer languages to communicate with computers. We understand many languages, but computer only understand one language that is machine language whose alphabet has only two characters, which are 0 and 1.
010 101 111 000 110
110 000 111 101 010
Hey! I am not an alien; I can not use 0 and 1 to communicate with computer?110 000 111 101 010
This problem has a solution, whenever you talk with an outsider, if you do not understand his/her language then you finds a person who can understand the outsider language and can translate it in your language. In the same way we use language translators to convert any computer language into machine language.
There are many computer languages that are used to communicate with computer as C/C++, Java, Visual Basic, Pascal, GW-Basic and many more. And all the languages have their own translators to translate their language in machine language (001101001).
Introduction:
C language is a general purpose and high-level language, which was originally designed for use on the Unix Operating System by Dennis Ritchie. The Unix Operating System, UNIX applications and tools have been coded in C. And of course C is not a machine language, and a C program can easily be edited to make it work on various platforms. It also has a language translator which is called compiler.
Compiler reads the entire source program and converts it into an object file which your deaf computer can read.
The Standard C Header Library:
It is a collection of pre-written routines or functions that are needed by programmers in various applications again and again. No program will work correctly without functions and routines which are contained by the header files. Instead of wasting time on including the entire code of a long header file in each program, we save our time by declaring header files, not all but the ones which you are apt to use in your program.
Here I share the complete list of header files:
<stdio.h> Standard Input \ Output
<stdlib.h> Commonly used General Utilities
<stdarg.h> Variable Arguments
<math.h> Mathematics
<assert.h> Diagnostics
<ctype.h> Character Handling
<errno.h> Errors
<float.h> Characteristics of Floating Types
<limits.h> Sizes of Integral Types
<locale.h> Localisation
<setjmp.h> Non Local Jumps
<signal.h> Signal Handling
<stddef.h> Common Definitions
<string.h> String Handling
<time.h> Date and Time
Installing C in windows:
Turbo C++ is an IDE (Integrated Development Environment), which gives us a single platform where we can code our program, compile it and see the output.
May I ask you a question? Why download Turbo C++ for C language?
Because, Turbo C++ is a single IDE, where you can code in both programming languages (C and C++). If you move to C++ then you do not need to get any other software.
First of all! Get a CD (Compact Disk) of "Turbo C++ 3.0" from market, or download it. You can setup C language like other programs. And try to install it in C: drive.
Starting Turbo C++:
You can start Turbo C++ by opening the TC.exe file, which is located in C=>TC=>BIN=>TC.exe
Or by ms-dos command? Which is C: > cd\tc\bin, press return and then type TC.exe and again return.
Saving Source File:
The file, in which you write code/statements for your program is called Source file in programmer’s language. To save your file click SAVE from file menu and goto any directory where you want to save your file and write your file name including the .c extension, because C language source files are saved in this extension to give you an understanding of what language you are working in. If you save with extension .cpp then the compiler will think it like a C++ source file and give you errors.
Compiling your Source File:
Compiling is the process in which Compiler reads the entire source file, translate it and make an object file (with .obj extension), which is readable by your unintelligent computer.
In order to see your program running, you have to compile it by selecting COMPILE from Compile menu, and then to run it by clicking RUN from Run menu.
Writing/Coding your first C Program:
When you have started Turbo C++, go to file menu and click "New". And then an IDE will be opened where you can code your program, this screen would be like notepad screen but not white like in notepad.
Do not be afraid, we will not work here in machine language, we will write our program in C language and its C's work to translate it into machine language (0 and 1) using his translator (compiler). Write this program in IDE and compile it.
#include <stdio.h>
void main(void) {
printf ("Hello World \n");
}
Output:-
Hello World
Let's have a look on above program, the first line tells the compiler to include functions or commands or routines from the header file stdio.h.
void in the second line tell that we are not taking any parameters and a function called main is declared. This function is called first whenever you run your program, and void in brackets means that we are not taking any kind of argument.
Hey! I am not able to see the screen, it vanish away quickly. How can I see it?
Every problem comes with a solution, so this has also one, you have to end this program by adding getch(); statement in the end of main function.
Why don’t you write it earlier? Well, what will happen if I change the main function name?
Do you have ever tried to drive a car with 3 wheels? Then. This main function is supporting function of your program; if you ignore it then compiler will ignore your file. Actually, when you run that program compiler will not be able to understand it. Main function is necessary to start your program. Compiler will treat it as a user-defined function and ignores it.
So how the “Hello World” is displayed in the output screen?
When our compiler reaches that line, it checks printf function in the header files, which is present in stdio.h, and then it reads the text within the brackets and then passes the text to be printed. \n is the new line character which causes the compiler to print the remaining text on the next line. Keep in mind that anything which gets start with a backslash \ is called an escape sequence.
The brackets {} are given to tell the computer to start main function from { and end it on } and the semicolon is called the statement terminator.
Let’s modify our program, Say you want to modify your first C program such that it prints Hello World on first line and I am here, no here on the second line:
#include <stdio.h>
void main(void) {
printf ("Hello World \n I am here");
printf (", no here");
}
Output:-
Hello World
I am here, no here
Sarang Mangi - Friday, February 18, 2011
just_sbm07@yahoo.com

No comments:
Post a Comment
What you want to say about this post. Feel free to leave comments. Comments help us improve and it tell us that you are there in World.