//What does this program print?#include <iostream>using namespace std;#define foo1( a ) a * aint j = 6;inline intfoo2( int a ) { return a * a;}voIDgoo1( int& x ){ x = 3;}voIDgoo2( int x ){ x = 3;}int main(){ int i,j = 12; cout << "foo1 = " << foo1( 3 + 2 ) << "\n"; cout << "foo2 = " << foo2( 3 + 2 ) << "\n"; i = 5; goo1( i ); cout << "goo1 = " << i << "\n"; i = 5; goo2( i ); cout << "goo2 = " << i << "\n"; cout << " j = " << j << "\n"; cout << "::j = " << ::j << "\n";}
有人可以解释一下foo1 = 11.我一直在尝试不同的数字一小时,我无法确切地知道如何计算.
解决方法 foo1是一个宏.宏执行严格的查找和替换,因此foo1(3 2)被替换为3 2 * 3 2. 按照 *** 作顺序,3 2 * 3 2 = 3 6 2 = 11. 总结以上是内存溢出为你收集整理的解释一个中期C的例子全部内容,希望文章能够帮你解决解释一个中期C的例子所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)