Will the same C code for an AVR microcontroller work with any other type?
For example, if I program an ATmega328P with C, would the same code work in any other 8-bit type for example with ATmega168?


In that case, the answer happens to be yes. The only difference between the ATmega168P and 328P is the amount of flash memory -- so long as your program fits on the 168P (i.e, as long as it isn't larger than 16 KB), it'll run identically on that part.

In other cases… it depends. There are some subtle differences in peripherals and features across the AVR line, even in situations where peripherals have the same name. Compare the datasheets carefully for details.


  How about same question for using 8-bit uC's code for a 32-bit uC like AVR32?


AVR32 is a completely different architecture from 8-bit AVR; they have almost nothing in common besides the name. So you'd probably have to rewrite your program.