You are on page 1of 19

Chapter No.

Q1: What is a computer language? Briefly describe the major type


of the computer languages?
Ans: Computer Language
The computer works by executing instructions. Each instruction directs one
operation of the computer system. Several instructions are written to perform one
task. This set of instructions given to the computer to perform a task is called the
computer program.
The computer instructions are written in a specific manner and according to a set
of rules. These languages are divided into two main categories. These are given
below.
1. Low Level Languages
2. High Level Languages

Low Level Languages:


The computer language that is close to the machine language is called low level
language. There are two types of low level language. These are machine language and
assembly language.
Machine Language
The computer works with the arrangements of 0s and 1s. The arrangement of 0s
and 1s is called the binary code. This is the fundamental language of the computer.
Since the computer works only with 0s and 1s, the instructions written in binary code
are called the machine language.
The machine language is difficult to understand and learn. Every computer system
has its own machine language. A program written on one type of computer system
cannot run on another type of computer system.
Assembly Language
Assembly language was developed to make the programming task easier. Instead
of using the binary code, it uses symbols. The symbols are used to represent
instruction. Therefore, it is also known as the symbolic language. Since the assembly
language is close to the machine language, it is called the low-level language.
Writing a program in assembly language is easier than writing the program in
machine language. However, the assembly language is also machine-specific. It is
also hard to learn.
Assembly language is usually used for writing system software and firmware.

High-Level Languages
The programming languages that are close to human language are called high-
level languages. The instructions in these languages are more like human languages.
BASIC, FORTRAN, COBOLM, PASCAL, C, etc. are examples of high level
languages. Unlike low level languages, these languages are easier to learn. These
languages are used for writing application programs. For example, a high level
language may be used for writing a program for maintaining the budget of a company.
Q2: Distinguish between the source code and object code?

Source Code
A computer program written in a high level language is called the source code.
It is also called the source program. Since the computer works only with the binary
code, the programs written in high level languages cannot run directly on the
computer. They must be converted into the binary code for execution by the computer.
Object Code
A computer program written in the machine language is called the object code.
It is also called the object program. Since machine language is the native language of
the computer, a program written in machine language runs directly on the computer.
Q3: What are the language processors? Briefly describe their various
types?

Language Processors
The computer works only with the binary code. Therefore, the programs
written in high level languages must be converted into the machine language (binary
code) for execution by the computer. Special programs are used to convert a source
code into the object code. These programs are called language processors.
Every high level programming language has its own language processor. The
language processors are divided into two categories. These are given below
1. Compilers
2. Interpreters

Compiler
The language processor that translates programs written in a high level
language into the machine language as a whole is called the compiler. The compiler
translates the source program into the machine code or object code. It saves the
compiled program into another file called the object file. The computer directly
executes the object file. The program is compiled only once and can be executed a
number of times directly on the computer.
If there is any error in the source program, the compiler specifies the error at
the time of compilation. All errors must be removed before the compiler can
successfully compile the source program.

Interpreter
The language processor that executes a source program by translating and
executing one instruction at a time is called interpreter. If there is any error in the
instruction it indicates the error and program execution stops.
The interpreter translates the program instructions one by one and executes
them immediately. It does not create an object program. Thus the interpreter translates
the source program each time the program is executed. This method of translating and
executing a program is slow and time consuming. A BASIC language processor is an
example of Interpreter.
Q4: What are the Characteristics of High Level Languages?

Characteristics of High Level Languages:


The features and qualities of a language are called characteristics of the language.
These features distinguish a language from other languages. Some important
characteristics of high level languages are given below:

Not Machine Dependent


The high level languag4es are not machine dependent. Unlike a machine
language program that can be run only on the computer system for which it is written,
a high level program can be run on any computer system.

Can Be Implemented On a Variety of Machines


The program written in a high level language is called the source code. This
source code is first compiled and then executed on the computer system. A source
code can be compiled and executed on any computer system for which the language
compiler is available.

Well Defined Syntax and Standard


Each high level language has a standard syntax. The standard is published by
several International Organizations. An important Organization that publishes the
computer programming language standards is ANSI (American National Standards
Institute). The compilers are written according to the standard syntax of the language.

Relatively Easy to Learn


The instructions are written in English like words in high level languages. This
makes learning, understanding and writing program in high level languages easy.

Source is Understandable by another Programmer


Since the instructions are written in plain English words and according to the
standard syntax of the language, any computer programmer can understand a program
written by another programmer.
Q5: Explain the Advantage of High level Languages?
Advantages of High Level Languages
High level languages have several advantages over low level languages. Some
important advantages of these languages are:
Easy to Learn
The instructions written in high level languages are similar to the plain English
Instructions. This makes the high level languages easy to learn and use.

Machine Independent
A program written in a high level language can be used on any computer
system for which the compiler of the language is available.

Shorter Programs
The High level language programs are shorter than the programs written in
machine languages. A single instruction written in a high level language translates
into several machine language instructions.

Problem Oriented Languages


The high level languages are problem oriented languages. These are designed
to solve problems on the computer system. For example, a business oriented language
uses business term and the language for scientists and engineering calculations uses
scientific terms.

Easier to Understand
The program instructions in high level language are similar to the plain
English statement. This makes the program easy to understand. Anyone who is
familiar with the computer language can easily understand the logic of the program
written in a high level language.

Less Time Needed for Writing Programs


Several programmers can work on one program simultaneously. Thus a
program can be developed quickly.

Standards are Available


The syntax of the high level languages is standardized. The compilers are
written according to these standards.

Programming Aids are Available


Several tools or programs are available that help the writing of programs in
high level languages. These programs provide facilities for writing source code,
compiling and debugging of the programs. These tools have increased the seed of
writing programs in high level language.

Many Programmers are Available


The programming in machine languages was time consuming and difficult to
learn. This discourages people from learning these languages. On the other hand, the
programming in high level languages is easy and many people learn and use these
languages.
Q6: Briefly describe the history of development of C language?

Brief History of C:
C is a general purpose programming language. It was developed at AT & T
Bell Laboratories in 1972. it was designed and written by Dennis Ritche. It was
written as a part of the UNIX operating system. The UNIX system and its tools were
written in C. As the UNIX system spread, the C language also became popular.
Because of its capabilities as a medium level language, C language was used to
develop system software. It was also widely used to write software to control
industrial processes.
Q7: What is ANSI C Standard?

ANSI-C Standard:
The standard for a language specifies the form of the program written in that
language. It also specifies how programs are to be interpreted. The purpose of a
standard is to specify the syntax of the language and make it portable across various
computer systems
The standard for C language was first proposed by the American National
Standards Institute (ANSI) in late 1980s. In 1990, the International Standards
Organization als9o adopted the ANSI standard for C language. This is known as
ANSI/ISO C standard. This standard is now an internationally recognized standard
and almost all C compilers now follow the ANSI C standard.
Q7: What are the Advantages of C language?

Advantages of C language
Following are the advantages of C language:

Native Language of UNIX


C is the native language of UNIX. UNIX is a major operating system on
workstations, servers and mainframes. Also, many window based packages, database
programs, graphic libraries and other large application programs are written in C
language.

Medium Level Language


C is a medium level language. C has the characteristics of both a low level
language and a high level language. It allows direct manipulation of memory
addresses and data. It also has all the capabilities of a high level language and allows
the writing of programs independent of the computer system.

Portable Language
The C –programs written on one type of computer system can be easily used
on another computer system.

Small but Powerful Language


C is a small but very powerful language. It has fewer commands and
statements. This makes it easy to learn. It has very powerful operators and can directly
access the hardware of the computer system. This makes C a powerful language.

Case Sensitive Language


C is a case sensitive language. This means that a character written in lower
case is different from the same letter written in uppercase. All keywords of C
language are 9in lowercase. Much of the source program in C language is also written
in lowercase.

Efficient Language
Since C can directly access the hardware of the computer system and uses
fewer commands, the compiled C programs run more efficiently on the computer than
that of other languages.

Basis for C++


C is the basis for C++. The statements, commands and methodologies used in
C are also available in C++. Thus learning C is a first step towards learning C++.
Q8: What is the Structure of a C program?

Structure of C programs
The format according to which a program is written is called the structure of
the program. The structure of a C program consists of three main parts. These are
given below:

Preprocessor Directives
The main() function
C Statements

A program example is given below. The first statement of the program is a


preprocessor directive. This preprocessor directive has been written to include the
stdio.h header file. The second statement indicated the main function. The C
statements are written in the main function within curly braces.

#include <stdio.h>
main ()
{
printf ("This is my first Program");
}
Q9: what is the Purpose of Preprocessor directive?

Preprocessor Directives
The Instruction that are given to the compiler before the beginning of the
actual program are called preprocessor directives. These are also known as compiler
directives. These are written at the beginning of the source code.
These preprocessor directives start with a number sign (#) and the keyword
"include" or "define". They are the instructions or directives that tell the compiler to
take action(s) before compiling the source code. The program that handles the
preprocessor directives is called the preprocessor because it does some processing
before the compilation process starts.
For example, preprocessor directives are used to include header files in the
program. The preprocessor includes the specified header file into the source code
before compiling.
Q10: what are Header files and what are they used for?

Header Files
Header files are part of the C compiler and contain definitions of standard
library functions. There are several header files. Each header file contains definitions
of one type of functions only. For example, the math.h header file contains definitions
of mathematical functions available in C language.
Each header file has an extension .h. The preprocessor directive "include" is
used to add a header file into the program. The name of the file is written in angle
brackets (<>) after "#include" directive. The syntax to include a header file is:

#include <name of the header file>

Giving the name of the header file in angle brackets specifies that the header
file is located in the include directory of the compiler program.
The name of the header file can also be written in double quotes. When the
name of the file is written in double quotes. It specifies that the file is to be loaded
from the current directory. The syntax to include a header file is:

#include "name of the header file"

A header file is added if the functions defined in it are to be used in the


program. For example, the header file stdio.h had definitions of various built-in input
and output functions. This file is included in a program if any of its functions is used
in the program.
Q11: what is the main function in a C program?

The Main() Function


The "main()" function indicates the beginning of a C program. The "main()"
must be included in every C program. When a C program is executed, the control
goes directly to the main() function.
The statements within this function are the main body of the C program. If
main() function is not included, the program is not compiles and error message is
generated.
The syntax of the main() function is:

main()
{
program statements…
}
Q12: what are C statements?

C Statements

The statements of the program are written under the main() function
between curly braces {}. These statements are the body of the program. Each
statement in C ends with a semicolon(;).
C is a case sensitive language. The C statements are normally written
in lowercase letters but, in some cases, these can also be written in uppercase.
Q13: What are C keywords?

Keywords:
The words that are used by the language for special purposes are called
keywords. These are also called reserved words. These have predefined uses and
cannot be used for any other purpose in a C program. These are always written in
lower case
For example, in a C program, the keyword main is used to indicate the starting
of the program, include is used to add header files, int is used to declare an integer
type variable. All these words are keywords of C.
There are 32 words defined as keywords in C. Following is the completer list
of C keywords:

C Keywords:

auto double int struct


break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Q14: What are Token?

Tokens
A program statement consist of variable names, keywords, constants,
punctuation marks, operators, etc. In C, these elements of a statement are called
tokens. In the following program segment:

main()
{
int a, b;
}

main, {, }, int, a, b and punctuation marks (,) and (;) are tokens of the program.
Q15: What are Comments and what are they used for?

The Comment Statement


The comment statement is a non-executable statement. It is used to add
remarks or comments in a program. The comments are usually given to explain logic
of the program. The compiler ignores the comments given in the program.

In C, a slash asterisk (/*) combination is used to specify the beginning and


asterisk slash (*/) is used to mark the end of the comment statement. For example

/* this is my first program in C */


/* Java Language is similar to C */

In the above example, two lines indicate the comment statements. The comments can
be given at any place in the source program. For example, the comments can also be
given after a C statement as shown below:

Sum = a + c++; /*An example of Postfix operator*/


Sum = a + ++c; /*An example of Prefix Operator*/
Q16: Explain the Process of Creating a C program?

Creating C program:
There are four fundamental stages or steps in creating a C program. These
steps are Editing, Compiling, Linking and Executing a program. A brief description of
these steps is given below:

Editing
Writing, Changing and revising the source code is called editing. In this step
the source code of the program is written and edited. The source code is written in any
text editor. It is saved on the disk in an ASCII text file.
Most C compilers come with an editor for writing the source code. This editor
is specially designed for writing the source code of C programs. It provides features
that make the writing of the C source code easier. They highlight various parts of the
program in different colors. This makes the source code more readable.
However, any text editor can be used for writing the source code. The source
code is saved on the disk as an ASCII text file with an extension c.

Compiling
The converting of the source code into the machine code is called compiling.
The program that is used to convert the source code into the machine code is called
the compiler.
The compiler takes the source code file of the C program stored on the disk. It
converts it into the machine code or the object code. Object code is the intermediate
form of the program. In the first step, the compiler creates object code and saves it in
a new file on the disk. The file has an extension obj.
Before creating the object code, the compiler scans the source code for errors.
If there are errors in the source code, it does not compile the source code and indicates
the errors. All errors must be removed from the source code before creating the object
code of the program.

Linking
In this step the necessary libraries are linked to the object code. After linking
the libraries, the executable file of the program is created.
A C program may contain predefined routines and functions. These functions
are contained in separate files. These files are part of the C compiler and are called
library files or runtime libraries.
The linker can also detect errors. For example, if the source code uses a library
function that does not exist, the linker generates an error. Of there are errors, the
linker does not create the executable file. These are removed in the source code and a
new object file is created. The new object file is then linked to the libraries to create
executable file. The executable file is created with the .exe extension. This file is
directly run on the computer system.

Executing
In this step, the program is actually run on the computer system. The
executable file is run by giving it to the system loader. For example, In Windows
Operating System, when the name of an executable file is double clicked, the system
loader loads the file into the computer memory and executes it.
The executable file of the program may also contain certain errors. These
errors can produce wrong output or they may halt the system. These errors are located
and removed in the source code and the source code is again compiled to create a new
executable file.

Q17: What is a C Preprocessor?

Preprocessor
Every C source code contains certain preprocessor directives at the beginning
of the code. These directives are instructions for the C preprocessor.
Preprocessor is the part of the C compiler. Before translating the program into
the object code, the preprocessor carries out the preprocessor directives. These
directives start with the number sign (#). The most commonly used preprocessor
directives are #include and #define.
Usually preprocessor directives a meant to include a header file into the source
code. Before compiling the program, preprocessor includes the required header file
into the source code. The new source code is called the expanded source code. The
compiler then translates the expanded source code into the object code.

Q18: What is Debugging? What are different types of errors in a


program?

Debugging
Errors in a program are called "bugs" and tracking and removing these errors
is called debugging. There can be two main types of errors in a program. There are
given below.

Syntax Errors
The rules for writing statements of a computer programming language are
called syntax of the language. The program statements are written strictly according
to these rules. A single mistake in these rules causes an error. This error is called
syntax error. The compiler detects these errors. It does not compile a program that
contains syntax errors. These errors are easy to locate and remove.

Logical Errors
The errors in the logic of a program are called logical errors. The compile
cannot detect these errors. A program with logical errors runs correctly but it gives
wrong result.
The logical errors may occur due to the following reasons.
 The input data may be incorrect because the out put of the
program depends upon the input data
 The sequence of instructions used in a program may be correct
 A mathematical formula used in program instructions may be
incorrect. For example using a division operator (/) in a formula
when the multiplication operator (*) should have been used
causes wrong output.

These errors are most difficult to locate and remove. To track logical errors, all units
of the program are examined one by one.

You might also like