Professional Documents
Culture Documents
C
L a n g u a
Page 2 of 20
Machine language
The programs or instructions written in this language are in the form of binary
strings of (1) and (0) and these are called the binary code. It is the fundamental
language. The programs written in this language are executed directly by the
computer. The executing speed is very fast in machine language. There exists a
one to one correspondence.
Assembly language
Assembly language is similar to machine language in the sense that in most of
cases between the machine language instruction and the assembly language
instruction. However, instead of binary codes one may use symbolic codes in the
assembly language and obviously this is an advantage. For example, one might
use the symbolic code ADD instead of a binary code say 00011, to may also use
symbolic name instead of actual addresses. However, like the machine language,
the assembly language is very much dependent on the system and differs from
machine to machine.
It is called the mother language of computer. It was used for application and
system software developing.
2. High Level Languages
The programming languages which are close to human language are known as
high level languages. High level languages are programmer friendly but difficult
for hardware. The programs written in these languages are close to English
language. Other high level languages have their own rules (syntax) and character.
These languages are used in developing application software system software.
There are two further types of High Level Languages:
• Procedural Language
• OOP ( Object Oriented Languages)
Basic , Cobol, Pascal, Fortran and C language are the examples of Procedural
Languages whereas Visual Basic, Java, C ++ , etc are the examples of OOP
languages.
Q. What are Language processors or Language
Translators ?
Ans:
Language Processor Translators
When we write any program in high-level language, it does not run directly on
the computer. Therefore, the program has to be converted into machine language.
Page 4 of 20
The program which converts source program into an object program is called
language processor has two types.
• Interpreter
• Compiler
Interpreters
The language processors which execute a source program by translation and
execute one instruction at a time is called interpreter. If there is any error in the
instruction it indicates the error and program executing stops. The interpreter
translates the program instruction one by one and executes them immediately. It
does not create an object program. Thus the interpreter translates the source
program each time and the program is executed. In this method of translation and
execution, the processing speed is slow and times wasting. A basic language
processor is an example of interpreter.
Compiler
The language processor that translates program written in a high level
language into the machine language as a whole is called the compiler. If there is
any error in the source program, the compiler specifier the error at the time of
compilation. All errors must be removed before the compilation which leads to
successful compilation of the source program. The compiler generates an
intermediate kind of file called an object file. The computer directly executes the
object file.
Source program/code
The program which we write in High level language is called source
code/source program. The source program cannot be run directly on the computer.
It is translated into (binary code) or machine language for execution by the
computer.
Object Code
After compiling, the source code/source program, converts into machine
language and it is called object code/object program. The object program directly
executes on the computer.
Q. Write the Characteristics Of High Level Language?
Ans: The main characteristics of high-level language are.
1. These languages do not depend on machine but can be run on any
computer system.
C 5
2. The program which writes in high-level language is called source
code. The source program after compiling and execution, can be run an
any computer system.
3. An American National Standards Institute (ANSI) published the
standard for computer programming languages which has a standard
syntax
4. These high level languages are very close to human languages. The
high level languages are very easy to learn and can be understood by
another programmer.
Q. Write history of C Language.
Ans : Brief History C Language
C is a general purpose programming language C was created by Dennis
Ritchie at AT&T Bell Laboratories in 1972. C language is very popular language.
C language is a mid level language. It was written as a part of the unix operating
system. The unix system and its tools written is C. C language was used and
develop system software.
ANSI.C Standard
In 1989 a new version of the language was given by the ANSI (American
National Standards Institute) standard C. This version consists of many features.
Inter nationaly, the international standards organization ISO is responsible for
standardizing C language currently the ISO C standards in thus the final authority
that constitutes the C language programming language.
• Preprocessor directives
• The main( ) function
• Begin brace
• C statements or Start C programming
• End brace
The first statement of C program is preprocessor directive. With the help
of this we includes the header file.
For Example
# include <stdio.h>
C 7
The second function of C program is main( ) and next step begins with brace
which indicates to start programming, After begining braces C programming
starts or writes C statements and ending brace shows C program closing.
# include <stdio.h>
void main(void)
{
printf(“Welcome C language”)
}
Preprocessor Directives
The directives can be placed anywhere in a program, but are most often used
at the beginning of a file, before main( );
The first line of the structure.
# include <stdio.h>
might look like a program statements, but it is not . It is not part of a function
body and does not end with a semicolon, as program statements must. Instead, it
starts with a number sign (#). It is called a preprocessor directive. Recall that
program statements or instructions to the computer. A preprocessor directive, on
the other hand is an instruction to the compiler itself. A part of the compiler called
the preprocessor deals with these directives before it begins the real compilation
process.
Header Files
The use of header files is common in C. Whenever you use a library function
predefined, you will need to use a header files that contains appropriate
declarations. Header files also contain prototypes for the library functions.
Prototypes provide a way to avoid program errors. Each header file has a (.h) file
extension.
The #include Directive
The preprocessor directive # include tells the compiler to insert another file
into your source file. We should mention that you can use #include in two ways.
The angle brackets < and > surrounding the filenames.
# include <stdio.h>
Example indicates that the compiler should begin searching for these files in
the standard INCLUDE directory. This directory holds the header files supplied
by Boarland for the system. Instead of angle brackets around the filename, you
can also use quotation marks, as in
Quotation marks instruct the compiler to begin its search for the header file in
the current directory; this is usually the directory that contains the source file. You
normally use quotation marks for header files you write yourself. Quotation marks
or angle brackets work in case, but making the appropriate choice speed up the
compilation process slightly by giving the compiler a hint about where to find the
file.
The main( ) Function
All C programs are divide into units called “Function”. The main( ) is used in
the beginning of every program. It also controls the functions of ‘C’. That main( )
is a function. Every ‘C‘ program consists of one or more functions this program
has only one. No matter how many function there are in a ‘C’ program, main( ) is
the one to which control is passed from the operating system when the program is
run; it is the first function executed.
The word “void” preceding “main” specifies that the function main( ) will not
return a value. The second “void” in parentheses, specifies that the function takes
no arguments.
Curly Braces ({ })
After “main” uses this bracket. Also use this curly brace ({) before starting
the program. We use this curly brace (}) to close the program. The number of
only curly brackets used for opening the program must be equal to the no of
closing the program.
Statements Terminator or Semicolon (;)
When any line is finished, It is very necessary to put a semicolon on its end
point. This shows that this line has finished. If semicolon is not used, the program
will give errors.
Note:
Semicolon should not be used at the end of a loop and condition otherwise the
loop and condition will stop at that point immediately. Detail structure is given
below:
C 9
F u n c t i o n n a m e
O p e n i vn og i d m a i n ( v o i d )
b r a c e t o
d e l i m {i t b o d y
o f f u n p c r t i (i n oW t n f e l c o m e C L a n g u a g e
}
o n e s t as et e m m i ce no tl o n
C l o s i nT g h i s e n t i r e t Pe r r mo gi rn a a mt e s
b r a c e ct o n s i s t s o f e a a cf u h n c t i o n
d e l i m ci t a bl l o e dd y m a pi n r o( g ) r a m
o f f u n c t i o n s t a t e m e n t
[IDE]
IDE screen is displayed. However the edit window will automatically opened
with NONAME00.C. The IDE screen, which initially displays only a menu bar at
the top of the screen and a status bar below, will appear. The menu bar displayed
the menu name File, Edit, Search, Run, and so forth. The status bar tells you
what various function keys will do now, with a blank edit window awaiting us,
you type program.
Selection
from Shortcut Keys Action
Edit menu
Cut [Shirft] [Del] Delete block and write it to
clipboard
Copy [Ctrl] [Ins] Copy block to clipboard
Paste [Shirft] [Ins] Insert block from clipboard
at cursor
Clear [Ctrl] [Del] Delete block, do not write
to clipboard
C 13
To move a block of text, mark it, and then select Cut. The text will write to the
clipboard, replacing whatever was there before. Then position the cursor where
you want the block to go, and select Paste. The block will write at that location.
Compiling
The compiler converts the source file into object file. The object file, which has
an (OBJ) extension, contains machine-language instructions. That can be
executed by the computer.
(Press Key F9)
A Successful Compiling
Linking
In linking function make links with their own library file. This is called linking.
When we make a program, the functions of C language used in this program have
library file. It extension in (.LIB). After compiling there function make link with
their own library file and in this way, an executed file is (.exe) create.
(Press Key F9)
Page 14 of 20
A successful linking
Executing a Program
If there were no errors in the compiling or linking process, your are now ready to
run the program. You can do this from the (IDE) by selecting Run from the Run
menu, or by pressing the [Ctrl + F9] key combination.
The program has written a message to output screen, but not to the [IDE] screen.
To see the program’s output, select user screen from the window menu, or press
[Alt+F5]
output
Welcome C Language
Pressing any key take you back to the (IDE) screen.
Notes
• Compiling and linking F9
• Program Execution or Run program Ctrl + F9
• To see output screen Alt + F5
Q. Write a note on errors and its types.
Ans:
ERRORS
No one writes error free computer programs every time. It may be that you
were unclear on the syntax of particular statement, or that you made a typing
error. Such errors can be discovered by the compiler or by the linker, or by
various run time routines that the compiler builds into your program
automatically.
C 15
Compiler Errors
Suppose you have forgotten to type semicolon at the end of the statement in
FIRST.C. The result will be that, when you compile window in C. Instead of
displaying the success message, will show a positive number in this case, 2 in the
errors field. Click ok in the edit status window, a message window will appear at
the bottom of the screen. It will contain the following figer.
M E S S A G E
C o m p i l i n g F I R S T . C :
E r r o r F I R S T . C 6 : S t a t e m e n t m i s s i n g ;
E r r o r F I R S T . C 6 : c o m p u n d s t a t e m e n t
6 : 4M o d i I f n i es ed r t
Often one typing mistake will lead the compiler to issue several error
messages as happens here. It sees that the semicolon is missing. In the edit
window, the program line with the closing brace is highlighted, and the brace
itself is highlighted in a different color. This indicates the place where the
compiler found error. When it go to the brace, it realized that there should have
been a semicolon earlier, so it signaled the errors at that point.
Linker Errors
Errors can also appear during the linking process. For instance, suppose you
spell the word main as MAIN. (Remember that C is case sensitive language). The
program will compile correctly, but when you build or link it, the compile status
(or linker) window will show a link error. Now the message window will display
a line something like.
Page 16 of 20
M E S S A G E
C o m p i l i n g F I R S T . C :
L i n k i n g F I R S T . E X E
L i n k e r E r r o r : u n d e f i n e d s y m b o l _ m a i n i
6 : 4M o d i I f n i es ed r t
The linker must find a function called main; without this, it cannot create an
executable file. The linker does not highlight the offending line in the source file,
so you may sometimes have difficulty in tracking down such errors. However, in
this case the problem should be obvious.
Logical Errors
When you start writing more complex programs, you will often find that a
program compiles and links without errors, but nevertheless fails to operate as
intended. In such situations you will probably want to use C’s debugger features
to analyze what’s going on. You can single step through a program, watch
variables change as each.
Statement is executed, and performs other activities to help you analyze your
program’s aberrant behavior.
Note: When all the errors are corrected, press [F2] to save the source file, and
then [F9] to compile and link again.
C 17
EXERCISES
25. The two types of low-level languages are __________ language and
__________ language.
26. The language which contains both the high level and low level language is
called __________ level language.
27. The High level language are programmer friendly but difficult for
__________.
28. There high level languages are used in developing __________ and
__________ software.
29. Basic stands for __________.
30. Cobol stands for __________.
31. Fortran stands for __________.
32. The processor has two types __________ and __________.
33. The language processors which executes a source program by translating
and execute one instruction at a time is called __________.
34. The program which we write in high level language is called __________
or __________.
35. After compiling, the source code converts into machine language, it is
called __________ code
36. The source program after compiling and execution, can be run an any
__________ system.
37. C is also a __________ language.
38. C Language is based on __________.
39. C language is very __________.
40. In C language any problem can be solved by a __________ of different
tools.
41. Header files also contain prototypes for the __________ functions.
42. All C programs are divided into units called __________.
43. The __________ is used in the beginning of every program.
44. C language is __________.
45. IDE stands for __________.
46. The key (F2) is used to __________ file.
47. ANSI stands for __________.
48. To compile a program __________key is used.
49. To execute a program __________ key is used.
50. __________ key is used to open a file.
51. __________ key is used to save a file.
Q3. Select the most suitable choice.
1. __________ language is used for business work.
a. Cobol b. Basic
c. Assembly d. C
2. C language is also called __________ language.
a. High level b. Mid level
C 19
c. Low level d. Machine
3. Mistakes in a computer program are also called __________.
a. Errors b. Syntax
c. Bugs d. Non of the above
4. The C statements are normally written in __________ letters
a. Upper-case b. Reserved word
c. Lower case d. Non of the above
5. C language is a __________ language.
a. Procedure oriented b. Function oriented
c. Object oriented d. Non of the above
6. __________ is an extension of header file.
a. (.h) b. (.obj)
c. (.c) d. (.cpp)
7. __________ is an extension of library file.
a. (.h) b. (.lib)
c. (.c) d. Non of the above
8. To compile a program __________ key is used.
a. F9 b. F7
c. F8 d. None of the above
9. __________ key is used and save a file.
a. F5 b. F3
c. F9 d. F2
Page 20 of 20
ANSWER EXERCISE.