Monday, February 6, 2012

Programming/theory Questions

Programming/theory Questions :

1 When is a switch statement better than multiple if statements?

A) switch statement is generally best to use when you have more than two
conditional expressions based on a single variable of numeric type.

2 What is the difference between goto and longjmp() and setjmp()?

A) goto statement implements a local jump of program execution, and the
longjmp() and setjmp() functions implement a nonlocal, or far, jump of
program
execution. General...

3 What is an lvalue?

A) 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 ...

4 Array is an lvalue or not?
A) An lvalue was defined as an expression to which a value can be assigned.
Is
an array an expression to which we can assign a value? The answer to this
question is no, because an array...

5 What is page thrashing?
A) Some operating systems (such as UNIX or Windows in enhanced mode) use
virtual
memory. Virtual memory is a technique for making a machine behave as if it
had
more memory ...

6 What is a const pointer?

A)The access modifier keyword const is a promise the programmer makes to the
compiler that the value of a variable will not be changed after it is
initialized. The compiler will enforc...

7 When should the register modifier be used? Does it really help?

A) The register modifier hints to the compiler that the variable will be
heavily used and should be kept in the CPU's registers, if possible, so
that it
can be accessed faster. There ar...

8 when should the volatile modifier be used?
A) The volatile modifier is a directive to the compiler's optimizer that
operations involving this variable should not be optimized in certain ways.
There are two special cases in which...

9 Can a variable be both const and volatile?
A) Yes. The const modifier means that this code cannot change the value of
the
variable, but that does not mean that the value cannot be changed by means
outside this code. For instance...

10 How reliable are floating-point comparisons?
A) Floating-point numbers are the "black art" of computer programming. One
reason why this is so is that there is no optimal way to represent an
arbitrary
number. The Institute of Elect...

11 How can you determine the maximum value that a numeric variable can hold?
A) For integral types, on a machine that uses two's complement arithmetic
(which is just about any machine you're likely to use), a signed type can
hold
numbers from –2(number of bits –...

12 When should a type cast be used?
A) There are two situations in which to use a type cast. The first use is to
change the type of an operand to an arithmetic operation so that the
operation
will be performed properly.&n...

13 When should a type cast not be used?
A) A type cast should not be used to override a const or volatile
declaration.
Overriding these type modifiers can cause the program to fail to run
correctly.

14 Is it acceptable to declare/define a variable in a C header?
A) global variable that must be accessed from more than one file can and
should
be declared in a header file. In addition, such a variable must be defined
in
one source file. Variable...

15 What is the difference between declaring a variable and defining a
variable?
A) Declaring a variable means describing its type to the compiler but not
allocating any space for it. Defining a variable means declaring it and also
allocating space to hold the variable

16 Can static variables be declared in a header file?
A) You can't declare a static variable without defining it as well (this is
because the storage class modifiers
static and extern are mutually exclusive). A static variable...

17 What is the benefit of using const for declaring constants?
The benefit of using the const keyword is that the compiler might be able to
make optimizations based on the knowledge that the value of the variable
will
not change. In addition, th...

18 What is the easiest sorting method to use?
The answer is the standard library function qsort(). It's the easiest sort
by
far for several reasons:
It is already written.
It is already debugged.
...

19 What is the quickest sorting method to use?
The answer depends on what you mean by quickest. For most sorting problems,
it
just doesn't matter how quick the sort is because it is done infrequently or
other operations take sign...

20 How can I sort things that are too large to bring into memory?
A sorting program that sorts items that are on secondary storage (disk or
tape) rather than primary storage (memory) is called an external sort.
Exactly
how to sort large data...
21 What is the easiest searching method to use?
Just as qsort() was the easiest sorting method, because it is part of the
standard library, bsearch() is the
easiest searching method to use. If the given array is in th...

22 What is the quickest searching method to use?
A binary search, such as bsearch() performs, is much faster than a linear
search. A hashing algorithm can provide even faster searching. One
particularly
interesting and fast method ...

23 What is hashing?
To hash means to grind up, and that's essentially what hashing is all about.
The heart of a hashing algorithm is a hash function that takes your nice,
neat
data and grinds it into so...

24 How can I sort a linked list?
Both the merge sort and the radix sort are good sorting algorithms to use
for
linked lists.

25 How can I search for data in a linked list?
Unfortunately, the only way to search a linked list is with a linear search,
because the only way a linked list's members can be accessed is
sequentially.
Sometimes it is quicker to ...

26 How do you redirect a standard stream?
Most operating systems, including DOS, provide a means to redirect program
input and output to and from different devices. This means that rather than
your
program output (stdout) go...

27 How can you restore a redirected standard stream?
The preceding example showed how you can redirect a standard stream from
within your program. But what if later in your program you wanted to
restore the
standard stream to its or...

28 What is the difference between text and binary modes?
Streams can be classified into two types: text streams and binary streams.
Text streams are interpreted, with a maximum length of 255 characters. With
text
streams, car...

29 How do you determine whether to use a stream function or a low-level
function?
Stream functions such as fread() and fwrite() are buffered and are more
efficient when reading and writing text or binary data to files. You
generally
gain better performance by usin...

30 How can I open a file so that other programs can update it at the same
time?
Your C compiler library contains a low-level file function called sopen()
that
can be used to open a file in shared mode. Beginning with DOS 3.0, files
could
be opened in shar...

31 How can I make sure that my program is the only one accessing a file?
By using the sopen() function you can open a file in shared mode and
explicitly deny reading and writing permissions to any other program but
yours.
This task is accomplished by usin...

32 What is Preprocessor?
The preprocessor is used to modify your program according to the
preprocessor
directives in your source code. Preprocessor directives (such as #define)
give
the preprocessor s...

33 What is a macro, and how do you use it?
A macro is a preprocessor directive that provides a mechanism for token
replacement in your source code. Macros are created by using the #define
statement.
Here is...

34 What will the preprocessor do for a program?
The C preprocessor is used to modify your program according to the
preprocessor directives in your source code. A preprocessor directive is a
statement (such as #define) that ...

35 How can you avoid including a header more than once?
One easy technique to avoid multiple inclusions of the same header is to use
the #ifndef and #define
preprocessor directives. When you create a header for your program, ...

36 Can a file other than a .h file be included with #include?
The preprocessor will include whatever file you specify in your #include
statement. Therefore, if you have the line
#include <macros.inc>
in you...

37 What is the benefit of using #define to declare a constant?
Using the #define method of declaring a constant enables you to declare a
constant in one place and use it throughout your program. This helps make
your
programs more maintainable, b...

38 What is the benefit of using an enum rather than a #define constant?
The use of an enumeration constant (enum) has many advantages over using the
traditional symbolic constant
style of #define. These advantages include a low...

39 How are portions of a program disabled in demo versions?
If you are distributing a demo version of your program, the preprocessor can
be used to enable or disable
portions of your program. The following portion of code shows h...

40 Is it better to use a macro or a function?
The answer depends on the situation you are writing code for. Macros have
the
distinct advantage of being more efficient (and faster) than functions,
because
their corresponding code...

41 What is the difference between #include <file> and #include "file"?
When writing your C program, you can include files in two ways. The first
way
is to surround the file you
want to include with the angled brackets < and >. This me...

42 Can you define which header file to include at compile time?
Yes. This can be done by using the #if, #else, and

No comments:

Post a Comment