Skip to content
Snippets Groups Projects
Commit 0c2d48b9 authored by Jonas Riedel's avatar Jonas Riedel
Browse files

Upload New File

parent 4ba80bed
Branches
No related tags found
No related merge requests found
program pointer_exercise
implicit none
! Declare variables
integer, target :: a = 5
integer, pointer :: ptr
! Point ptr to variable a
! Modify the value of a using ptr
! Print the modified value of a
write(*,*) "The modified value of a is:", a
end program pointer_exercise
program pointer_exercise_2
implicit none
type ListElement
integer :: element
type(ListElement), pointer :: next => null()
end type ListElement
type List
type(ListElement), pointer :: head => null()
end type List
type(List):: myList
!Allocate storage for the first (head) element of the list
!Insert the number 1 as the first (head) element of the list
!Allocate storage for the second element of the list
!Insert the number 2 as the second element of the list
!Write the first and second element of the list
!Deallocate the second element of the list
!Verify that there is no second element in the list using associated()
!Try writing the first and second element of the list again
!Try writing a hypthetical third element of the list
!Deallocate the first element of the list
end program pointer_exercise_2
program pointer_exercise_3
implicit none
type ListElement
integer :: element
type(ListElement), pointer :: next => null()
end type ListElement
type List
type(ListElement), pointer :: head => null()
end type List
type(List) :: myList
type(ListElement),pointer :: current
integer :: input
allocate(myList%head)
write(*,*) "Please enter the integer of the first element of the List:"
read(*,*) myList%head%element
current => myList%head
!Write a do loop that inserts new integers given by the user into the List until the user inputs a negative number.
!Use the pointer "current" and the integer "input"
end program pointer_exercise_3
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment