Under INA 245(i), if a family or employment-based immigrant visa or labor certification was filed for an immigrant before the cut off date of April 30, 2001 and the immigrant was physically present or living in the US (legal or not legal), the immigrant will usually not have to leave the U.S. to process and pick up a green card abroad at a U.S. consulate. Many times, an immigrant's US citizen spouse filed after this cut off date for the immigrant who entered the US illegally and the immigrant is forced to leave the US to consular process the green card. The problem is that once an immigrant departs (leaves) the US, s/he could face a 10 or 3 year bar or permanent bar to re-entering the US for being in the US illegally. So, many times, departing the US just because the immigrant seems eligible for a green card could be a very risky move.
But many times an immigrant can avoid leaving the US if the immigrant's mother or father was sponsored under 245(i) for an immigrant visa (i.e., by their sister or brother or former spouse if married at that time), the immigrant was under 21 when their mother or father's visa petition was filed, and the petition was "approvable when filed" (either shown by an approval notice or if pending, underlying proof of qualification for the visa status).
For example, if Juan was 19 years old in April 2001 and his mom's (who is also illegally in the US) brother - Juan's uncle, sponsored Juan's mother for an immigrant visa based on the brother/sister relationship by April 30, 2001, Juan would be able to use that old filing to "grandfather" under the expired provision of 245(i), assuming he hasn't left the US, to file a new case based on marriage to a US citizen and will be able to get his green card in the US without having to leave to consular process even though Juan entered the US illegally.
Important: Figuring out if you qualify for 245(i) grandfathering can be complicated. Always consult an attorney to determine if this option is available to you and never leave the US after a period of illegal presence until you consult with at least one competent immigration attorney so you know your options and any potential consequences of your departure.