-
-
-
Find the factorial of given positive integer.
Consider the following code for finding the factorial of given positive integer IFACT=1 DO 100 I=2,N,2 100 IFACT = IFACT*i*(i-1) For which value of N, the above FORTRAN code will not work ? 1. N is even 2. N is odd 3. N is perfect number 4. N mod 3 =0
-
-
-
-
How can I do this using recursion ?
For the List class, add a Boolean-valued function that determines whether the data items in the linked list are arranged in ascending order. How can I do this using recursion ?
-
-
Overload subscript operator
How will you Overload subscript operator with more than one dimension?
-
Matrix Manipulation library in C
Let's say you want to develop a Matrix manipulation library in pure C (not C++). For example, you want to define a "matrix_multiply" function to get A * B, how to declare the function and how to implement it? Make sure that you consider error handling stuff, e.g., a 2*2 matrix and a 3*3 matrix cannot multiply, and how to detect and deal with the situation when you pass a 3*3 matrix as a parameter which...
-
Program listing IP addresses of all active clients.
Write a program which sends a token on network and give the list of IP addresses of all the client currently active ?(program is running on server)
-
Different ways of expressing the same idea.
main(){ char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);}
Ans:mmmm
aaaa
nnnn
Explanation:s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting... -
Recursion C program.
main() { static int var = 5; printf("%d ",var--); if(var) main(); }
Ans:5 4 3 2 1 Explanation:When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively. -
Loops in C programming.
main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j -
When should the volatile modifier be used?
The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the volatile modifier is desirable. The first case involves memory-mapped hardware (a device such as a graphics adaptor that appears to the computer’s hardware as if it were part of the computer’s memory), and...
-
How can you restore a redirected standard stream?
The preceding example showed how you can redirect a standard stream from within your program. But what if later in your program you wanted to restore the standard stream to its original state? By using the standard C library functions named dup() and fdopen(), you can restore a standard stream such as stdout to its original state. The dup() function duplicates a file handle. You can use the dup()...
-
How do you determine whether to use a stream function or a low-level function?
Stream functions such as fread() and fwrite() are buffered and are more efficient when reading and writing text or binary data to files. You generally gain better performance by using stream functions rather than their unbuffered low-level counterparts such as read() and write(). In multi-user environments, however, when files are typically shared and portions of files are continuously being locked,...
-
How can I open a file so that other programs can update it at the same time?
Your C compiler library contains a low-level file function called sopen() that can be used to open a file in shared mode. Beginning with DOS 3.0, files could be opened in shared mode by loading a special program named SHARE.EXE. Shared mode, as the name implies, allows a file to be shared with other programs as well as your own. Using this function, you can allow other programs that are running to...
-
How can I make sure that my program is the only one accessing a file?
By using the sopen() function you can open a file in shared mode and explicitly deny reading and writing permissions to any other program but yours. This task is accomplished by using the SH_DENYWR shared flag to denote that your program is going to deny any writing or reading attempts by other programs. For example, the following snippet of code shows a file being opened in shared mode, denying...
-
What will the preprocessor do for a program?
The C preprocessor is used to modify your program according to the preprocessor directives in your source code. A preprocessor directive is a statement (such as #define) that gives the preprocessor specific instructions on how to modify your source code. The preprocessor is invoked as the first part of your compiler program’s compilation step. It is usually hidden from the programmer because it is...
C Interview Questions
Ans