C Language Functions Interview Question Part 2

 

C Language Functions Interview Question Part 2

1. How would you use the functions randomize () and random ()?

randomize ():initiates random number generation with a random value.
random ():generates random number between 0 and n-1;

2. What do the functions atoi (), itoa () and gcvt () do?

atoi () is a macro that converts integer to character.
itoa () It converts an integer to string
gcvt () It converts a floating point number to string.

3. How would you use the functions fseek (), freed (), fwrite () and ftell ()?
fseek (f,1,i) Move the pointer for file f a distance 1 byte from location i.
fread (s,i1,i2,f) Enter i2 dataitems,each of size i1 bytes, from file f to string s.
fwrite (s,i1,i2,f) send i2 data items, each of size i1 bytes from string s to file f.
ftell (f) Return the current pointer position within file f.
The data type returned for functions fread, fseek and fwrite is int and ftell is long int.

4. What is the difference between the functions memmove () and memcpy ()?
The arguments of memmove () can overlap in memory. The arguments of memcpy () cannot.

5. Difference between linker and linkage?
Linker converts an object code into an executable code by linking together the necessary built in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.

6. What is the purpose of main () function?
The main () function in C is the most vital part of a program. The program execution occurs from the main () function. The main () function may contain any number of statements and they are sequentially executed. main () function can in turn call other functions.

7. What is friend function?
The function declaration should be preceded by the keyword friend. The function definitions do not use either the keyword or the scope operator (::). The functions that are declared with the keyword friend as friend function. Thus, a friend function is an ordinary function or a member of another class.

8. What are user defined functions in C language?
C provides programmer to define their own function according to their requirement known as user defined functions. Means except built in functions user can also define and write small programs as functions to do a task relevant to their programs, there functions should be codified by the user, so that such functions can perform the task as desired by user. Suppose, a programmer wants to find factorial of a number and check whether it is prime or not in same program. Then, he/she can create two separate user-defined functions in that program: one for finding factorial and other for checking whether it is prime or not.

9. How user-defined function works in C Programming?
#include void function_name (){
…………….
…………….
}
int main(){
………..
………..
function_name ();
………..
……….. }
As mentioned earlier, every C program begins from main () and program starts executing the codes inside main () function. When the control of program reaches to function_name () inside main () function. The control of program jumps to void function_name () and executes the codes inside it. When, all the codes inside that user-defined function are executed, control of the program jumps to the statement just after function_name () from where it is called. Remember, the function name is an identifier and should be unique.

10. What are the advantages of user defined functions?
Advantages of user defined functions are,
• User defined functions helps to decompose the large program into small segments which makes programmer easy to understand, maintain and debug.
• If repeated code occurs in a program. Function can be used to include those codes and execute when needed by calling that function.
• Programmer working on large project can divide the workload by making different functions.

11. What is the return type of a function?
The Return Function determines whether a Function will return any value to the Function. If a Function is declared with the void Keyword or if a Function Contains a void then that’s means a Function Never Returns a value. Means a Function will Executes his statements one by one. And if a Function Contain any other data type means if a Function Contains int or float then the Function must return a value to the user.

12. What is argument list?
A Function may have zero or More Arguments. So that if we want to call a Function. Then we must have to Supply Some Arguments or we must have to pass some values those are also called as the Argument List. So that The Argument List is the total Number of Arguments or the Parameters those a Function Will takes. So that we must have to supply some arguments to the Function. The Arguments those are used by the Function Calling are known as the Actual Arguments and the Arguments those are used in the Function declaration are Known as the Formal Arguments, When we call any Function then the Actual Arguments will Match the Formal Arguments and if a proper Match is Found, then this will Executes the Statements of the Function otherwise this will gives you an error Message.

13. What are the two ways of calling a function?
The function call is made as follows:
return_type = function_name (arguments);
There are Two Ways for Calling a Function , they are
• Call by value
• Call by reference

14. What is Call by value?
Call by Value: when we call a Function and if a function can accept the Arguments from the Called Function, Then we must have to Supply some Arguments to the Function. So that the Arguments those are passed to that function just contains the values from the variables but not an Actual Address of the variable.
So that generally when we call a Function then we will just pass the variables or the Arguments and we doesn’t Pass the Address of Variables , So that the function will never effects on the Values or on the variables. So Call by value is just the Concept in which you must have to Remember that the values those are Passed to the Functions will never effect the Actual Values those are Stored into the variables.

15. What is Call by reference?
Call By Reference: When a function is called by the reference then the values those are passed in the calling functions are affected when they are passed by Reference Means they change their value when they passed by the References. In the Call by Reference we pass the Address of the variables whose Arguments are also Send. So that when we use the Reference then, we pass the Address the Variables.
When we pass the Address of variables to the Arguments then a Function may effect on the Variables. Means When a Function will Change the Values then the values of Variables gets Automatically Changed. And When a Function performs Some Operation on the Passed values, then this will also effect on the Actual Values.

16. What is the difference between Call by value and Call by reference?
When using Call by Value, you are sending the value of a variable as parameter to a function, whereas Call by Reference sends the address of the variable. Also, under Call by Value, the value in the parameter is not affected by whatever operation that takes place, while in the case of Call by Reference, values can be affected by the process within the function.

Follow me on social media: