DEVFYI - Developer Resource - FYI

C Interview Questions and Answers

Part:   1  2  3  4  5  6  7  8  9  10  11  12  13  14  15   16  17  18  19  20  21  22  23  24  25  26  27  28 

(Continued from previous part...)

What is modular programming?

If a program is large, it is subdivided into a number of smaller programs that are called modules or subprograms. If a complex problem is solved using more modules, this approach is known as modular programming.


How can you determine the maximum value that a numeric variable can hold?

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 1) to +2(number of bits 1) 1. An unsigned type can hold values from 0 to +2(number of bits) 1. For instance, a 16-bit signed integer can hold numbers from 2^15 (32768) to +2^15 1 (32767).


How can you determine the maximum value that a numeric variable can hold?

How reliable are floating-point comparisons? 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 Electrical and Electronic Engineers (IEEE) has developed a standard for the representation of floating-point numbers, but you cannot guarantee that every machine you use will conform to the standard.
Even if your machine does conform to the standard, there are deeper issues. It can be shown mathematically that there are an infinite number of real numbers between any two numbers. For the computer to distinguish between two numbers, the bits that represent them must differ. To represent an infinite number of different bit patterns would take an infinite number of bits. Because the computer must represent a large range of numbers in a small number of bits (usually 32 to 64 bits), it has to make approximate representations of most numbers.
Because floating-point numbers are so tricky to deal with, it’s generally bad practice to compare a floating-point number for equality with anything. Inequalities are much safer.


How can you determine the maximum value that a numeric variable can hold?

Which expression always return true? Which always return false? expression if (a=0) always return false
expression if (a=1) always return true


How many levels deep can include files be nested?

Even though there is no limit to the number of levels of nested include files you can have, your compiler might run out of stack space while trying to include an inordinately high number of files. This number varies according to your hardware configuration and possibly your compiler.


What is the difference between declaring a variable and defining a variable?

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. You can also initialize a variable at the time it is defined.


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 using the SH_DENYWR shared flag to denote that your program is going to deny any writing or reading attempts by other programs.
For example, the following snippet of code shows a file being opened in shared mode, denying access to all other files:
/* Note that the sopen() function is not ANSI compliant... */ fileHandle = sopen(“C:DATASETUP.DAT”, O_RDWR, SH_DENYWR);
By issuing this statement, all other programs are denied access to the SETUP.DAT file. If another program were to try to open SETUP.DAT for reading or writing, it would receive an EACCES error code, denoting that access is denied to the file.

(Continued on next part...)

Part:   1  2  3  4  5  6  7  8  9  10  11  12  13  14  15   16  17  18  19  20  21  22  23  24  25  26  27  28 

C Interview Questions and Answers