C program page2 | Sample Papers

Samplepaperz.blogspot.com

Samplepaperz.blogspot.com
Home » » C program page2

C program page2

Written By Blogger on 26 August 2013 | 22:18


Which is more efficient, a switch statement or an if else chain?

The differences, if any, are likely to be slight. The switch statement was designed to be efficiently implementable, though the compiler may choose to use the equivalent of an if/else chain (as opposed to a compact jump table) if the case labels are sparsely distributed.
Do use switch when you can: it's certainly cleaner, and perhaps more efficient (and certainly should never be any less efficient).

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 all.

How can I ensure that integer arithmetic doesnt overflow?

The usual approach is to test the operands against the limits in the header file <limits.h> before doing the operation. For example, here is a ``careful'' addition function:
int
chkadd(int a, int b)
{
if(INT_MAX - b < a) {
fputs("int overflown", stderr);
return INT_MAX;
}
return a + b;
}

How can I handle floating-point exceptions gracefully?

On many systems, you can define a function matherr which will be called when there are certain floating-point errors, such as errors in the math routines in <math.h>. You may also be able to use signal to catch SIGFPE

What is Hungarian Notation? Is it worthwhile?

Hungarian Notation is a naming convention, invented by Charles Simonyi, which encodes information about a variable's type (and perhaps its intended use) in its name. It is well-loved in some circles and roundly castigated in others. Its chief advantage is that it makes a variable's type or intended use obvious from its name; its chief disadvantage is that type information is not necessarily a worthwhile thing to carry around in the name of a variable.


You can DOWNLOAD more C programming interview questions and answers from here.

 Job vacancy for Computer Science Engineering Freshers

Other Important Downloads









26 Aug 2013 Albert Augustine

0 comments:

Post a Comment

Search