C Bit Bank
C Bit Bank
Fundamentals of C Language
Structure of a C program:
Solution:
Writing of programs may involved the following steps:
1. Understanding the problem.
2. Planning the method of solution.
3. Development of the methods by using suitable algorithms,
flowcharts, etc.
4. Coding the instructions in a programming language.
5. Transforming the instructions into machine readable form
(using an input medium)
6. Program testing and debugging.
7. Documentation of the works involved in the production of
the program.
2
Notes:
Solution: The header file <stdio.h> is used to include and link standard
input/output functions in a C program.
4
Q. What is Preprocessor?
Q. What is an assembler?
Solution:
The language in which a programmer writes programs is called
source language. It may be a high-level language or an assembely
language. A program written in a source language is called a source
program. When a source program is converted into machine code by an
assembler or compiler it is known as an object program.
A text editor is a program which is used to type and edit your computer
program or document. Commonly used editors are Turbo, NE(Norton
Editor)Vi editor(Used in UNIX system)
Solution:
Assembler: An assembler is a computer program or translator which
translates an assembly language program into a machine language
program.
Solution:
Q.8: State the differences between compiler and interpreter. State the
advantages and disadvantages of machine level language, assembly
language and high level language.
Solution:
The following table lists the differences between a Compiler and an
Interpreter.
Compiler Interpreter
1 Scans the entire program Translates the program line
first and then translates it by line.
into machine code
2 Converts the entire program Each time the program is
to machine code; when all executed, every line is
the syntax errors are checked for syntax error and
removed execution takes then converted to equivalent
place. machine code.
3 Slow for debugging Good for fast debugging
4 Execution time is less Execution time is more
Solution:
9
Testing and debugging are two separate tasks. The differences between
these two processes are outlined in Table 1:
Table 1: Differences between Testing and Debugging
Testing Debugging
1. Testing is the process in which Debugging is a process in which
a program is validated. program errors are removed.
2. Testing is complete when all Debugging is a process that ends
desired verifications in terms of only temporarily, because
the specifications have been subsequent execution of a
performed program may uncover other
errors thereby restarting the
debugging process.
3. Testing can and should be Debugging is a reactive
planned. It is a definable task in procedure, which stems from
which the how and what to test testing. It cannot be planned
can be specified. Testing can be ahead of time. The best that can
scheduled to take place at a be done is to establish guidelines
specific time in the development of how to debug and develop a
cycle. list of “what to look for.”
4. Testing can begin in the early Debugging, on the other hand,
stages of the development effort. cannot begin until the end of the
Of course, the test themselves development cycle, because it
must be run near the end of a requires an executable program.
project, but the decisions of what
to test, how to test, with what
kind of data can and should be
completed before the coding is
started.
Solution: When the compiler detects an error, the computer will display
an error message.
(a) Syntax error messages: Syntax error or compilation errors are
detected and displayed by the compiler as it attempts to translate our
program. If a statement has a syntax error, it cannot be translated and our
program will not executed.
10
(b) Runtime error messages: Run time errors are detected by the
computer and are displayed during execution of a program. A run-time
error occurs when the program directs the computer to perform an illegal
operation, such as dividing a number by zero. When run-time error
occurs, the computer will stop executing our program and will print a
diagnostic our program and will print a diagnostic message that indicates
the line where the error was detected.
Q. What is an lvalue?
Solution:
An lvalue is an expression to which a value can be assigned. The lvalue
expression is located on the left side of an assignment statement, whereas
an rvalue is located on the right side of an assignment statement. Each
assignment statement must have an lvalue and an rvalue. The lvalue
expression must reference a storable variable in memory. It cannot be a
constant.
Q.: What's the difference between #include <> and #include "" ?
Solution: The <> syntax is typically used with Standard or system-supplied headers,
while "" is typically used for a program's own header files.
Solution:
A compile-time error is an error that occurs when a program is being
compiled. Examples: syntax errors such as omitting a required semicolon, using an
undeclared variable, using a keyword for the name of a variable.
A run-time error is an error that occurs when a program is running. Numeric
overflow and division by zero are examples of run-time errors.
Solution:
3GL‟s supply a few small operations which can be combined with great
flexibility to accomplish almost anything. The cost, of course, is in time-consuming
detail in which each and every bit of code must be cast.
12
Solution:
Top-down design is the technique of breaking down a problem into various
major tasks needed to be performed. Each of these tasks is further broken down into
separate subtasks, and so on till each subtask is sufficiently simple to be written as a
self-contained or procedure module. The entire solution of the problem will then
consist of a series of simple modules.
Top-down approach is made use of in the system analysis and design process.
The top-down approach, starting at the general levels to gain an
understanding of the system and gradually moving down to levels of greater details is
done in the analysis stage. In the process of moving from top to bottom, each
component is exploded into more and more details.
Thus, the problem at hand is analyzed or broken down into major
components, each of which is again broken down if necessary.
A program should be documented as it provides the information that one
needs in order to use a program. This information includes a number of different
items. These items are:
a. A description of the application area of the program or what will this program
do?
b. A description of the input data that the program requires.
c. A description of the output produced by the program.
d. A description of the commands needed to start the program.
e. A description of the kinds of interactions that are possible with the program.
f. An explanation of all the messages that the program can produce.
g. A discussion (in non-technical terms) of the performance capabilities and
limitations of the program.
So long as computers are programmed by human beings, computer programs will
be subject to errors. Programming errors are known as bugs and the process of
detecting and correcting these errors is called debugging. In general, testing is the
process of making sure that the program performs the intended task, and debugging
is the process of locating and eliminating program errors.
13
Solution:
Top-down design is the technique of breaking down a problem into various
major tasks needed to be performed. Each of these tasks is further broken down into
separate subtasks, and so on till each subtask is sufficiently simple to be written as a
self contained or procedure module. The entire solution of the problem will then
consist of a series of simple modules.
Top-down approach is made use of in the system analysis and design process.
The top-down approach, starting at the general levels to gain an
understanding of the system and gradually moving down to levels of greater details is
done in the analysis stage. In the process of moving from top to bottom, each
component is exploded into more and more details.
Thus, the problem at hand is analyzed or broken down into major
components, each of which is again broken down if necessary.
&&&&&&&&&&