Not necessarily... You will need to check that they memory modules are in fact the same as they can be different. A quick check is to go to your Apple icon menu > then about this mac... you will see the memory type something like

1GB 667 MHz DDR2 SDRAM

You might find that the new iMacs are 800MHz and the Macbook Pro is 667 MHz depending on exactly how old it is.