Friday 30 January 2015

Fortran Technical Interview Questions and Answers (Part7)

51. What directory is used by the compiler for compiling a Fortran Program? Where does f77 live? 
For the work in this class, you should assume that everything happens in whatever directory you are in when you type the "f77". Type "pwd" if you don't know the answer to this question. The executable file called "f77" resides both in /bin and /usr/bin on these machines. This is very unsual. To locate an executable file use the "whereis" command (e.g. "whereis f77"). Unfortunately the manual pages on f77 aren't connected properly and are listed under IBM's other name for their compiler, "xlf". Try "man xlf" for more information on the compiler, but don't expect too much. IBM likes to force people to buy manuals and special CD-ROM packages.

52. How do you use a logical variable? What is stored there? 
Most frequently, logical variables are used in association with IF statements. When you want to set a logical variable LVAR to true you use "LVAR=.TRUE.". For false use "LVAR=.FALSE." In practice the computer usually stores an integer 0 in memory for false and integer 1 for true. The normal logicalvariable occupies 1 byte of space.

53. Do spaces mater in equations? 
No. Spaces are generally added for clarity. Some compilers get upset if you write things like " INTEGERI,J" rather than INTEGER I,J". Simple neatness will keep you out of these problems. Remember that a space is required in column 6 if you aren't continuing from the previous line. The following are all equivalent:
x=x*y**2*sin(x)
x=x * y**2 * sin(x)
x = x * y ** 2 * sin ( x )

54. Why are go to statements bad, and what can we do to avoid them? 
GO TO is bad only to the extent that it makes coding difficult to read. I think they are an important part of the language, but should be used sparingly. Use of DO loops and IF, THEN, ELSE constructs (along with good indentation habits) whenever practical will take care of most of the problem. In extreme cases where you have many nested IF statements, with many lines contained in each THEN/ELSE option set, even good indentation habits will not improve code clarity. Consider breaking code off into subroutines, or go back to GOTO constructs where you can at least trace labelnumbers with an editor.
More Questions & Answers :-
Part1  Part2  Part3  Part4  Part5  Part6

No comments:

Post a Comment