They both share a common ancestor called Archosaur, but then evolved separately. Theres a decent high level description of that here, but the key part is:
Crocodiles and dinosaurs share a deeper connection than most people realize, both belonging to the group Archosauria, which emerged approximately 250 million years ago. This relationship makes crocodiles more closely related to birds (the surviving dinosaur lineage) than they are to other reptiles like lizards and snakes. The archosaur lineage split into two main branches: the Pseudosuchia (crocodile line) and the Avemetatarsalia (dinosaur and pterosaur line). During the Triassic period, both groups flourished and diversified, producing a remarkable array of body forms and ecological adaptations. This shared heritage explains certain similarities between crocodilians and dinosaurs, including their four-chambered hearts, complex respiratory systems, and parental care behaviors—traits that distinguish them from other reptile groups.
They both share a common ancestor called Archosaur, but then evolved separately. Theres a decent high level description of that here, but the key part is: