C Functions Interview Preparation Guide
Download PDF

C Language Functions frequently Asked Questions in various C functions job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting

45 C Functions Questions and Answers:

1 :: Do you have any idea how to compare array with pointer in C?

The following declarations are NOT the same:
char *p;
char a[20];

The first declaration allocates memory for a pointer; the second allocates memory for 20 characters.

2 :: Do you know pointer in C?

A pointer is an address location of another variable. It is a value that designates the address or memory location of some other value (usually value of a variable). The value of a variable can be accessed by a pointer which points to that variable. To do so, the reference operator (&) is pre-appended to the variable that holds the value. A pointer can hold any data type, including functions.

3 :: Tell me what is NULL pointer in C?

A null pointer does not point to any object.
NULL and 0 are interchangeable in pointer contexts.Usage of NULL should be considered a gentle reminder that a pointer is involved.
It is only in pointer contexts that NULL and 0 are equivalent. NULL should not be used when another kind of 0 is required.

4 :: What is #pragma statements?

The #pragma Directives are used to turn ON or OFF certain features. They vary from compiler to compiler.
Examples of pragmas are:

#pragma startup // you can use this to execute a function at startup of a program
#pragma exit // you can use this to execute a function at exiting of a program
#pragma warn –rvl // used to suppress return value not used warning
#pragma warn –par // used to suppress parameter not used warning
#pragma warn –rch // used to suppress unreachable code warning

5 :: Explain the advantages of using macro in C Language?

In modular programming, using functions is advisable when a certain code is repeated several times in a program. However, everytime a function is called the control gets transferred to that function and then back to the calling function. This consumes a lot of execution time. One way to save this time is by using macros. Macros substitute a function call by the definition of that function. This saves execution time to a great extent.

6 :: Do you know what are bitwise shift operators in C Programming?

The bitwise operators are used for shifting the bits of the first operand left or right. The number of shifts is specified by the second operator.

Expression << or >> number of shifts

Ex:

number<<3;/* number is an operand - shifts 3 bits towards left*/
number>>2; /* number is an operand – shifts 2 bits towards right*/

The variable number must be an integer value.

For leftward shifts, the right bits those are vacated are set to 0. For rightward shifts, the left bits those are vacated are filled with 0’s based on the type of the first operand after conversion.

If the value of ‘number’ is 5, the first statement in the above example results 40 and stored in the variable ‘number’.

If the value of ‘number’ is 5, the second statement in the above example results 0 (zero) and stored in the variable ‘number’.

7 :: Tell me the use of bit field in C Language?

Bit Fields allow the packing of data in a structure.

This is especially useful when memory or data storage is at a premium

The maximum length of the field should be less than or equal to the integer word length of the computer.some compilers may allow memory overlap for the fields.Some store the next field in the next word.
C lets us do this in a structure definition by putting :bit length after the variable:
struct pack
{
unsigned int funny_int:9;
}p;

Also, Boolean datatype flags can be stored compactly as a series of bits using the bits fields. Each Boolean flag is stored in a separate bit.

8 :: Tell us the use of fflush() function in C Language?

In ANSI, fflush() [returns 0 if buffer successfully deleted / returns EOF on an error] causes the system to empty the buffer associated with the specified output stream.
It undoes the effect of any ungetc() function if the stream is open for input. The stream remains open after the call.
If stream is NULL, the system flushes all open streams.

However, the system automatically deletes buffers when the stream is closed or even when a program ends normally without closing the stream.

9 :: Do you know the difference between exit() and _exit() function in C?

The following are the differences between exit() and _exit() functions:

- io buffers are flushed by exit() and executes some functions those are registered by atexit().

- _exit() ends the process without invoking the functions which are registered by atexit().

10 :: What is function prototype in C Language?

The basic definition of a function is known as function prototype. The signature of the function is same that of a normal function, except instead of containing code, it always ends with semicolon.

When the compiler makes a single pass over each and every file that is compiled. If a function call is encountered by the compiler, which is not yet been defined, the compiler throws an error.

One of the solution for the above is to restructure the program, in which all the functions appear only before they are called in another function.

Another solution is writing the function prototypes at the beginning of the file, which ensures the C compiler to read and process the function definitions, before there is a change of calling the function. If prototypes are declared, it is convenient and comfortable for the developer to write the code of those functions which are just the needed ones.