In English, the words 
this and that (when not used as a 
conjunction) can be thought of as having two meanings each.
-  I like this cat. That dog bit me. This girl is beautiful. That statement is false. 
- I like this. You liked that.  This is beautiful.  That is not true.
-  A more specific version of THE.  "I like the cat" can be made more specific by saying "I like this/that cat". 
-  A standalone pronoun that is NOT a substitute for THE.
We could not say "I like the", but we can say "I like this/that."
It's annoying that in English the word "this" is identical in these two cases.  
In Hungarian, of course, it's more logical. The two uses of "this" are translated differently:
   
-  ez a; az a   this; that 
- ez; az  this; that 
 
Before we apply any endings, let's look at the two versions in nominative (dictionary) form.
- Ez a macska fehér   This cat is white.
 Az a macska fekete    That cat is black.
 Ez az alma piros    This apple is red.  N.B the vowel means a becomes
az (like a becomes an in English)
 Az az alma zöld    That apple is green.
- 
Ez macska    This is a cat.
 Az kutya    That is a dog.
 Remember how we drop van from these, so in reality we're saying 
ez macska (van) ; az kutya (van).
Now let's put some endings onto the (pro) nouns.
The easiest is the accusative.
Remember, we apply   -t to the object of a verb.
- Én szeretem Ágit     I like Ági. 
- Én ettem almákat     I ate apples. 
- Én látom a kutyát     I see the dog. 
    
1: When the object is not a single word (Ági, alma, kutya)
but has this/that prefixing it, i.e. is case (1) above, when we're using it as a more specific form of the, then 
we must apply the ending to both parts:
- Én látom ezt a kutyát     I see this dog.   
- Én látom azt a kutyát     I see that cat. 
2: When we use this/that as a standalone pronoun, we apply endings to the (only) word
- Én szeretem ezt     I like this/it.   
- Én szeretem azt     I like that. 
 
 
Assimilation of endings is very important.  
As we have seen, we apply an ending to 
the noun itself and also to the qualifiying pronoun:
Én látom ezt a kutyát     I see this dog.
It's easy to see that we simply add the -t to both the ez/az and the noun.
However, the above is the simplest case.  Most other  
noun cases
require that the ez/az is modifed in some way.           
Let's take -ban as an example.  We want to say, "I live in this house."  That is our objective. 
-  ház     house
-  ez a ház    this house
-  
én lakom      I live (reside) 
-           
In = -ban/ben
Now we must start with 
ez a ház     this house
and apply -ban/ben
to it, to give us in this house. 
We do this by putting -ban or 
-ben on both the ez and on the noun:
-  
ez+(ban/ben)
    
a
     
ház+(ban/ben)
 
(Of course we choose either ban OR ben based on
vowel harmony).
Let's adjust the ház first:
The correct choice is -ban, because ház is a back-vowel word.
So far we have:
Now we must adjust ez.  
The correct choice of -ban or -ben is 
-ben, because this agrees with 
ez.  
N.B.  our choice of harmonious variant for the ez/az is independent of our choice for the noun itself!
We have so far:
  
This is when the assimilation occurs.
The 
-z in 
ez/az 
changes into the first consonant of the ending!
We then put in the -ben to get 
ebben.
Overal, the change is:
-      ez + ben = ebben
-  
ebben a házban
Altogether:
Én lakom ebben a házban.  QED.
If we wanted to say, "I live in that house," we would start with 
- 
az a ház
- 
az+ban = abban
- 
Én lakom abban a házban.
 
Here is a list the main noun endings, showing how the final 
-z in 
ez/az assimilates into the first consoonant of the new ending.
We also have
ezen/azon     on this/that
but there is no assimilation here becase the ending, -on/en,
doesn't start with a consonant (a requirement for the assimilation).
-        Lakom abban a városban I live in that city 
 
-        Laksz ebben a városban You live in this city 
 
-        Lakom abban a épületben I live in that building 
 
-        Laksz ebben a épületben You live in this building 
 
Note how when the -ban/-ben is applied to 
ez/az, its vowel harmonises with ez/az, not with the 
final object.
  
úsztam a tengerben.  
Benne, láttam halakat.  
 
I swam in the sea.  In it, I saw fish. 
  
Of course, ez 
and az
can receive endings without needing a noun (like in situation (2) above).
Then, the same rule applies to ez/az.
-  Én lakom ebben     I live in this
-  Én lakom abban     I live in that
-  Ági beszél erről     Ági speaks about this
-  Ági beszél arról     Ági  speaks about that
  
We apply the plural
to ez/az
as normal:      
1. More specific case of the (plural):
- ezek a ... -k     these 
- azok a ... -k     those
- ezek a kutyák fehérek    
these dogs are white
- azok a kutyák feketék    
those dogs are black
Of course they can still take noun case endings exactly like the singular brothers:
- Én látom ezeket a kutyákat    
I see these dogs
- Én látom azokat a házakat    
I see those houses
- Mi lakunk ezekben a házakban    
We live in those houses
- Ő laknak azokban a házakban    
They live in those houses
N.B. The assimilation does not happen for ezek/azok
The assimilation that we saw happening to the -z
in 
ez/az
does NOT happen to the trailing 
-k in 
ezek/azok. 
They simply take the noun endings
without any change (execpt for endings starting with 
-v-
as normal)
- ezekhez/azokhoz     toward these/those
- ezeknél/azoknál     by/at these/those
- ezekben/azokban     in these/those
- ezekkel/azokkal     with these/those 
 N.B. the effect visible here is not the assimilation of the  
-k in 
ezek/azok, 
rather it's the gemination of the 
-v-
in 
-val/vel
.
2. Standalone noun
Standalone nouns can take endings too:
- Szereted ezeket    
You like these
- Szereti azokat    
He likes those
 
The word "that" can be used as a conjuction:  I see that you are here.  It doesn't matter that you're late.
This is given by the ever-present Hungarian word, hogy.  Click to see the page about 
hogy.