"I do know that al-Qaeda is in Iraq and that's why I have said we should continue to strike al-Qaida targets," he said.
Obama said he wanted to withdraw US forces from Iraq to concentrate on removing al-Qaeda in Afghanistan and Pakistan and that he would reserve the right to hit the group, although he did not specify an air or ground attack.
McCain has repeatedly attacked Obama - and Obama's Democratic rival Hillary Clinton - for saying they would withdraw the troops.
Analysts say the exchange showed the two candidates consider each other to be possible general election rivals in the upcoming November elections.
Meanwhile Michael Bloomberg, the New York mayor, said he would not run as an independent candidate despite widespread speculation he could enter the race.
And on the Democratic side Clinton on Thursday was preparing to unveil a new childhood nutrition and poverty proposal in a speech at Ohio University's child care development centre.
However Clinton suffered a blow to her campaign on Wednesday when veteran civil rights campaigner and Georgian congressman John Lewis, a superdelegate, switched his allegiance from Clinton to Obama, saying he felt the Illinois senator was a symbol of "change".
The two Democratic candidates are preparing for crucial primary contests in Ohio and Texas - which both hold large numbers of delegates needed to clinch the nomination - on March 4.
McCain has already all but clinched the Republican nomination, with a commanding delegate lead over rival Mike Huckabee, the former Arkansas governor, and Texas congressman Ron Paul.