variables - Fortran unassigned array -


I am just starting to learn Fortran, and I have come to this issue. Consider the following simple code. Random INTEGER, dimension (12) :: array print *, array and program random

array not assigned Is done, but can be printed, and it has some random elements and many zeros. However, if I consider a small array, then I say

  INTEGER, DIMENSION (5) :: array   

then print the array All the elements = 0. I wonder what's going on here?

When you define an array and try to see the values ​​before it starts (By printing) Meaning, the behavior is undefined. It depends on the compiler on the compiler. While a compiler can automatically set all the values ​​to zero (many of us think that this is the default), another compiler can set it completely in random values, which is why you have array values Sometimes you are not seeing zero and sometimes.

However, there are options to start an assigned array for zero at the level of many compiler packages. It is always advised that anyone should start an array before using it!

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -