C Interview Questions and Answers


What is the best way of making my program efficient?

By picking good algorithms, implementing them carefully, and making sure that your
program isn't doing any extra work. For example, the most microoptimized character-copying
loop in the world will be beat by code which avoids having to copy characters at

When worrying about efficiency, it's important to keep several things in perspective.
First of all, although efficiency is an enormously popular topic, it is not always
as important as people tend to think it is. Most of the code in most programs is
not time-critical. When code is not time-critical, it is usually more important
that it be written clearly and portably than that it be written maximally efficiently.
(Remember that computers are very, very fast, and that seemingly ``inefficient''
code may be quite efficiently compilable, and run without apparent delay.)

It is notoriously difficult to predict what the ``hot spots'' in a program
will be. When efficiency is a concern, it is important to use profiling software
to determine which parts of the program deserve attention. Often, actual computation
time is swamped by peripheral tasks such as I/O and memory allocation, which can
be sped up by using buffering and caching techniques.

Posted by:Richards