Fortran Interview Questions and Answers
Most Frequently Asked Fortran Interview Questions
When a programmer writes the subroutine statement in a program, then subroutine can modify its arguments, but it does not return a value.
subroutine name(arg1, arg2, ....)
[declarations, including those for the arguments]
[executable statements]
end subroutine [name]
A subroutine is invokes using the call statement.
While writing a big program or if the functions and subroutines need to be used in more than one program then the programmer use module. A module is like a complete package where a programmer can keep the functions, subroutines. A module basically splits the program into multiple files.
A module contains two parts-
- a specification part for the statements declaration
- a includes a section for the subroutine and the function definitions
This is the favorite interviewer question in Fortran interview questions.
module name
[statement declarations]
[contains [subroutine and function definitions] ]
end module [name]
In Fortran, there is a feature of Implicit typing which means there is no need of declaring the variables before the use of the variables so the first letter of the variable name will determine the type of the variable. i, j, k, l, m, n are taken as integer numbers and other as real numbers.
The excellent programming practice is that the variables should be declared at the starting of the program so implicit none statement disables the implicit typing so that variables can be announced at the starting of the program
A number are those number s which has two parts real number and an imaginary number. Cmplx() function in Fortran creates a complex number. Cmplx() function produces a result where the real and the imaginary parts are the single precision regardless of the type of the input arguments.
Reserved words are those words which cannot be identifiers. Fortran has no reserved words, but Fortran has identifiers like END, PROGRAM, DO.
The variables in Fortran is declared by using the type statement at the beginning of the program. The syntax for declaring a variable is:-
type-specifier :: list
Here type-specifier can be: -INTEGER, REAL, COMPLEX, LOGICAL AND CHARACTER and the list is the name of the variables that can be separated with commas
For example:-
- INTEGER:: Total, Mean
- REAL:: Average
- CHARACTER(10) :: Surname, Name
((10 is the length value that must be there with the CHARACTER specifier. CHARACTER specifier can hold the string not more than 10 characters))