function-c language question and answer

Jan 11 • Resources • 1461 Views • 3 Comments on function-c language question and answer

Q1. What is a static function?
Ans1: It is a function whose scope is limited to the current source file. Scope refers to the visibility of a function or variable.

Q2. Is it possible to execute code even after the program exits the main()?
Ans2: 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 pointers to the atexit().

Q3. Using exit() is same as using return()?
Ans3: No. The exit() is used to exit from your program and the return is used to return from a function and return control to the calling.

Q4. Explain the use of fflush()?
Ans4: It is used to empty the buffer associated with the o/p stream.

Q5. 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.

Q6. What is virtual function?
Ans6: It is a member function that is declared within a base class and redefined by a derived class.

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

Q8. 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;
}

Ans8: 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.

3 Responses to function-c language question and answer

  1. Shruit Priya says:

    In today’s competitive world to get into the most growing industry sector that is the IT sector the minimum computer proficiency required is the basic knowledge of C language. I believe that C language is the most basic and essential among all the programming languages. So I would recommend all who desire to join an IT industry to read this article to get the very basic and fundamental knowledge about the C language.

  2. sanjana kumari says:

    C language has now become an essential as well as compulsory qualification which one should bear if he or she desires to join any industry in IT sector.. For proper knowledge about the language one must have fundamental knowledge and clear concepts are the various functions which are used while writing programs in C. I think everyone who is in a need of proper fundamental knowledge about C language and functions used in it must go through this article.

  3. Shaheen Khan says:

    Ques regarding function of C is available here. C is middle level lang should know to every student of technical field of any branch. Every thing is depends on coding and with the use of function we make code more efficient.

« »