Language in C Interview Questions and Answers

Ques 31. The access( ) function...

Ans. The access( ) function checks for the existence of a file and also determines whether it can be read, written to or executed. This function takes two arguments the filename and an integer indicating the access mode. The values 6, 4, 2, and 1 checks for read/write, read, write and execute permission of a given file, whereas value 0 checks whether the file exists or not. Following program demonstrates how we can use access( ) function to check if a given file exists.

Ques 32. How do I convert a floating-point number to a string?

Ans. Use function gcvt( ) to convert a floating-point number to a string. Following program demonstrates the use of this function.#include <stdlib.h>

main( ){char str[25] ;float no ;int dg = 5 ; /* significant digits */

no = 14.3216 ;gcvt ( no, dg, str ) ;printf ( "String: %s\n", str ) ;}

Is it helpful?
YesNoAdd CommentView Comments

Ques 33. What is a stack ?

Ans. The stack is a region of memory within which our programs temporarily store data as they execute. For example, when a program passes parameters to functions, C places the parameters on the stack. When the function completes, C removes the items from the stack. Similarly, when a function declares local variables, C stores the variable's values on the stack during the function's execution. Depending on the program's use of functions and parameters, the amount of stack space that a program requires will differ.

Ans. A node in a tree can have any number of branches. While a binary tree is a tree structure in which any node can have at most two branches. For binary trees we distinguish between the subtree on the left and subtree on the right, whereas for trees the order of the subtrees is irrelevant.Consider the following figure...

This above figure shows two binary trees, but these binary trees are different. The first has an empty right subtree while the second has an empty left subtree. If the above are regarded as trees (not the binary trees), then they are same despite the fact that they are drawn differently. Also, an empty binary tree can exist, but there is no tree having zero nodes.

Is it helpful?
YesNoAdd CommentView Comments

Ques 35. How do I use the function ldexp( ) in a program?

Ans. The math function ldexp( ) is used while solving the complex mathematical equations. This function takes two arguments, a double value and an int respectively. The order in which ldexp( ) function performs calculations is ( n * pow ( 2, exp ) ) where n is the double value and exp is the integer. The following program demonstrates the use of this function.