C Functions

  Home  C Language  C Functions


“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 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’.

 231 views

2⟩ 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.

 235 views

3⟩ 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.

 223 views

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

 223 views

5⟩ 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.

 223 views

6⟩ 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.

 224 views

8⟩ 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.

 217 views

10⟩ 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.

 216 views

11⟩ Can you please explain the difference between strcpy() and memcpy() function?

► Memcpy() copies specific number of bytes from source to destinatio in RAM, where as strcpy() copies a constant / string into another string.

► Memcpy() works on fixed length of arbitrary data, where as strcpy() works on null-terminated strings and it has no length limitations.

► Memcpy() is used to copy the exact amount of data, whereas strcpy() is used of copy variable-length null terminated strings.

 219 views

13⟩ What is the difference between malloc() and calloc() function in C Language?

The following are the differences between malloc() and calloc():

- Byte of memory is allocated by malloc(), whereas block of memory is allocated by calloc().

- malloc() takes a single argument, the size of memory, where as calloc takes two parameters, the number of variables to allocate memory and size of bytes of a single variable

- Memory initialization is not performed by malloc() , whereas memory is initialized by calloc().

- malloc(s) returns a pointer with enough storage with s bytes, where as calloc(n,s) returns a pointer with enough contiguous storage each with s bytes.

 208 views

14⟩ What is the difference between strcpy() and memcpy() function in C Programming?

The following are the differences between strcpy() and memcpy():

- memcpy() copies specific number of bytes from source to destinatio in RAM, where as strcpy() copies a constant / string into another string.

- memcpy() works on fixed length of arbitrary data, where as strcpy() works on null-terminated strings and it has no length limitations.

- memcpy() is used to copy the exact amount of data, whereas strcpy() is used of copy variable-length null terminated strings.

 229 views

16⟩ What is logical error?

Logical error are caused by an incorrect algorithm or by a statement mistypes in such a way

► That it doesn't violet syntax of language.

► Difficult to find.

 209 views

17⟩ What is recursion?

A recursion function is one which calls itself either directly or indirectly it must halt at a definite point to avoid infinite recursion.

 224 views

19⟩ What is actual argument?

Actual arguments are available in the function call. These arguments are given as constants or variables or expressions to pass the values to the function.

 209 views

20⟩ What is formal argument?

Formal arguments are the arguments available in the function definition. They are preceded by their own data type.

 214 views