The length of the first and last names

A quicker way to do that is to use describe call in Apex.

System.debug(Contact.FirstName.getDescribe().length); //Prints 40
System.debug(Contact.LastName.getDescribe().length); //Prints 80

It also works for All fields standard and custom.

That being said, you can use global describe to get lengths of all fields.

Src :

you can check details about fields on Contact SOAP API guide

FirstName - The contact’s first name up to 40 characters.

LastName - Required. Last name of the contact up to 80 characters.