Functions in C Language

Jan 11 • Resources • 2969 Views • 7 Comments on Functions in C Language

Q 1. What is a static function ?
Ans 1: A static function is a function whose scope is limited to the current source file. Scope refers to the visibility of a function or variable.

Q 2. Is it possible to execute code even after the program exits the main() function ?
Ans 2: C library consists of a function named atexit() that can be used to perform “cleanup” operations when your program terminates. You can set up a set of functions you want to perform automatically when your program exits by passing function pointers to the atexit() function.

Q 3. Is using exit() the same as using return?
Ans 3: No. The exit() function is used to exit from your program and the return function is used to return from a function and return control to the calling function.

Q 4. Explain the use of fflush() function ?
Ans 4: It is used to empty the buffer associated with the o/p stream.

Q 5. What is the difference b/w malloc() and calloc() ?
Ans 5: malloc allocates uninitialized memory while calloc initializes the allocated memory with a constant (0).
malloc uses single parameter while calloc uses 2 parameters to initialize memory.

Q 6. What is virtual function ?
Ans 6: A virtual function is a member function that is declared within a base class and redefined by a derived class.

Q 7. How many arguments can be used in a function ?
Ans 7: As such c language doesn’t put any restriction on number of arguments but arguments greater than 8 is not preferred.

Q 8. What is the output of the following program?
main()
{
int x=20;
int y=10;
swap(x,y);
printf(“%d %d”,y,x+2);
}
swap(int x,int y)
{
int temp;
temp =x;
x=y;
y=temp;
}
Ans 8: 10 22 (duplicate copy of arguments are generated on calling a function)

Q 9. What will be the output of the following code ?
output()
{
printf(“%p”,output);
}
Ans 9: Some address will be printed as function names are just addresses. Similarly output() is also a function and its address will be printed.

Q 10. What will be the output of the following code ?
main()
{
int i;
printf(“%d”,scanf(“%d”,&i)); // value 10 is given as input here
}
Ans 10: 1 as Scanf returns number of items read successfully. So number of items read is 1.

Tell us Your Queries, Suggestions and Feedback

Your email address will not be published.

7 Responses to Functions in C Language

  1. saurabh jajoo says:

    Functions are really a broad area of c and c++ languages.. Its a great try to make the functions familiar ones.

  2. sakshi chaudhary says:

    here present a good stuff which contains few basic questions on FUNCTIONS that help one to prepare for the interview..!!!

  3. Ankita Prajapati says:

    It was a great help for all to have an OVERVIEW of FUNCTIONS in C languageā€¦.before INTERVIEW…

  4. saurabh singh says:

    This article proves to be very helpful as it gives overview of important or frequently asked questions in interview.And it is good especially for last min. preparation.

  5. Roshani Mishra says:

    It gonna help students to get idea regarding ques. that can arise during an interview and they can have a quick review of the few imp. questions

  6. BHARTI PANDEY says:

    A good collection of QUESTIONS on C FUNCTIONS.It will be very helpful indeed…!!! Can prove very useful to boost your INTERVIEW PREPARATION…

« »