The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

drpositron (9) [Avatar] Offline
I recommend clarifying chapter 3, exercise 3. Also, it refers to the "above subroutine" as Listing 3.9, which follows and looks to be a portion of a main program. I understand what is intended, but perhaps the following is clearer:


In the previous subsection, I discussed the use of intent attribute in the declaration specification of arguments. intent(in out) can be used specifically to modify a variable in-place. Can you re-write the above subroutine (Listing 3.7) such that it adds b to a, and returns a so that its value is updated in the calling program? For example, the expected behavior should be:

Listing 3.9. Invoking a subroutine that modifies an input argument in-place.

program ch3ex3

integer :: a

a = 0
call add(a, 1)
write(*,*) a ! should write "1" to the console
call add(a, 2)
write(*,*) a ! should write "3" to the console

! your updated subroutine goes here
end program ch3ex3
Milan Curcic (44) [Avatar] Offline
Good catch with the Listing numbering! Will be fixed.

I also like your suggestion and helps being more clear and explicit so I will adapt it for the next release.

Cheers and thank you for making this a better book!