All Time Fortran Interview Questions
1. Can you give us a complete list of the Fortran commands and what they do?
No, but there are too many pages involved, and copyright problems with the standard Fortran manuals sold by computer software vendors. You’re stuck with the text and Web pages, buying something else from a bookstore, or buying a Fortran package for your PC.
2. Do we need to prompt the user for input on our programs?
Yes Always! In this section, any programmed “read” from the terminal must be preceded by writing some intelligible message asking for input.
3. How should one spell FORTRAN/Fortran?
FORTRAN is generally the preferred spelling for discussions of versions of the language prior to the current one (“90”). Fortran is the spelling chosen by X3J3 and WG5. In this document a feeble effort has been made to capitalize accordingly (e.g. vast existing software … FORTRAN vs. generic Fortran to mean all versions of the standard, and specifically the modern dialect, ISO 1539:1991).
4. How does Fortran 90 relate to FORTRAN 77?
With a few minor exceptions, Fortran 90 is a superset of X3.9-1978 FORTRAN.
But this does not mean that all “77” codes will port sans changes.
Many (if not most) programmers employed constructs beyond the ’77 standard, or rely on unspecified behavior (say, assuming that an OPEN of an existing file will position the file pointer to just past the last record already written) which has changed (that is to say, has become specified).
5. Why do you put so many lines of empty space in your programs?
I hope the lines aren’t totally empty. They should contain a “c” in column one. These “blank” lines are just to make the comments stand out from Fortran code lines or to highlight key blocks of a program.
6. What directory is used by the compiler for compiling a Fortran Program? Where does f77 live?
For the work in this section, 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.
7. 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 logical variable occupies 1 byte of space.
8. Where can I get a Fortran Compiler for IBM PC?
We can pick up one on the internet from the GNU project, but get a better package from MOC for about $80.00.
9. How do we know where various steps go in a Fortran program?
Some commands have special locations, but most are located by the needs of the specific program. The PROGRAM card is always first. Statements giving variable types (INTEGER, REAL, LOGICAL, CHARACTER, …) should precede “executable” statements. The END card must always be at the end of the program unit.
10. Why does not Fortran have intrinsic functions for something as simple as factorial?
Two reasons. Factorial isn’t all that common in heavy duty scientific and engineering applications. When it does occur, it almost always in a context where it is more computationally efficient to generate it as you go. You need 2! first then 3!, then 4!, etc. You are basically stuck doing a factorial within the context of a do loop unless you get really good and learn to write “recursive functions”, but then you are just fooling yourself and writing another form of do loop.
When you are taking the factorial of a large number and don’t need an exact answer you can resort to Stirling’s Approximation. A Fortran statement that will load the value of this approximation into the variable nfact is.
11. What can we do if our lines wrap around to the next line?
You have to get a feel for the location of the 72nd character position on the screen, or do a lot of counting. Once you hit column 72, you must hit the RETURN key, put some character (I like & or #) in column 6 of the next line then pick up typing where you left off. I usually stop before column 72 at some natural break point between variables:
123456789012345678901234567890123456789012345678901234567890123456789012
IF ( (X.LT.2.0.AND.Y.GT.30.0).OR.(X.GT.1000.0.AND.Y.LT.-40.))
& PRINT *,’ CALCULATION IS IN TROUBLE’
Since Fortran tends to ignore blanks, the extra ones in the above 2 lines don’t cause problems.
12. What is the advantage of an array over a spreadsheet format?
Both can store similar types of information in a neatly labeled and organized way. The advantage lies in where they are used. You have more control over how Fortran arrays are used than how the contents of aspreadsheet are used.
In addition for any given operation on an array of numbers, once the Fortran is written, it will do the job much faster than aspreadsheet. On the other hand, when operations are not complex and computer execution time is not a problem using the spreadsheet is probably your best bet.
13. Explain what is FORTRAN? What is the structure of the main program?
Fortran is referred as a third-generation programming language, built for numeric computation and scientific computing.
The main structure of the program
• Program name
• Declarations
• Statements
• Stop end
14. What makes Fortran a suitable language for scientific purpose?
• Built in support for arguments in subroutines
• Available built in support for complex numbers
• Rich set of intrinsic functions
• Support for array notation enabling operations on array sections
• For memory pointers strong aliasing rules, resulting in more efficient code after compilation
15. Explain how recursion is used in Fortran?
When one function calls to another function or itself, in a defined area of call is called recursion.
• It is denoted as subroutine as well, and it has the scope of the stack that directly supports the subroutines
• The return location on the stack that uses the subroutine is fixed and is adjacent to the subroutine code
• To call a function within a function recursion is used, and it allows easy calling of the function and minimizes writing of the code
16. Mention what are the rules involved in debugging?
For debugging the rules involved are
Code modification is not done until not sure about the bug by checking all the conditions and criteria
• Modular program is being used which defines the task, and it is placed in the debug statements that can ISOLATE some of the functioning of the code
• Combinations of inputs are carried out to get the desired output if strange results are noticed
• Use the tools provided with the debugger
17. Explain what does a DATA statement does?DATA statements assign a specific value into a Fortran variable before execution of the program. It takes the following form.
• DATA var-list /c-list/[[ ,] var-list/c-list/]
18. Explain what is the difference between a Subroutine and function Subprogram?
• The main difference is a subroutine never returns a value that is associated with its name. Which means that you never have to state a subroutine name in a type statement (Real, Integer…). All the information coming back from a subroutine passes through the argument list.
• Another difference is that a sub-routine need not have an argument list
19. Explain what is a logical variable? What does it store there?
Logical variables are used along with IF statements. When you want to set a logical variable to false, you use “LVAR=FALSE” and when you want to set as true, you use “LVAR=TRUE.” For false, computer usually stores an integer 0 in memory and, for true it stores as integer 1.
20. Explain what are the methods by which we can correct the syntax errors?
• To check the error during runtime or compile time of the program, compiler is used.
• It flags the error so that it can be corrected at a later stage, also it makes an error easier to understand
• With the help of inbuilt functions, errors can be reduced, and usage of the functions can be maximized
• To correct the listed errors and compile it again to recheck the errors windowing terminal is used
• Compiler can create a LIST FILE that place the list of the file in the EDITING BUFFER, and enables users to correct errors by placing program into another location.