文档介绍:There are two int variables: a and b, don't use “if”,“? :”,“switch”or other judgement statements, find out the biggest one of the two numbers.
答案:((a + b ) + abs( a - b ) ) / 2
如何打印出当前源文件的文件名以及源文件的当前行号?
答案:
cout V V __Fl LE__ ;
cout< v __LI NE__ ;
__FILE__和__LINE__是系统预定义宏,这种宏并不是在某个文件中定义的,而是由编译 器定义的。
main主函数执行完毕后,是否可能会再执行一段代码,给出说明?
答案:可以,可以用_onexit注册一个函数,它会在main之后执行int fn1 (void), fn2(void), fn3(void), fn4
(void);
void main( void )
(
String str("zhanglin");
_onexit( fn1 );
_onexit( fn2 );
_onexit( fn3 );
_onexit( fn4 );
printf( "This is executed first.\n");
}
int fn1()
(
printf( "nextAn");
return 0;
}
int fn2()
(
printf( "executed ");
return 0;
}
int fn3()
(
printf( "is ");
return 0;
}
int fn4()
printf( "This ");
return 0;
}
The _onexit function is passed the address of a function (func) to be called when the program
terminates normally. Successive calls to _onexit create a register of functions that are executed
in LIFO (last-in-first-out) order. The functions passed to _onexit cannot take parameters.
如何判断一段程序是由C编译程序还是由C+ +编译程序编译的?
答案:
ifdef __cplusplus
cout< v "c+ +
else
cout< v "c";
endif
文件中有一组整数,要求排序后输出到另一个文件中
答案:
#i nclude< iostream>
#i nclude<fstream>
using namespace std;
void Order(vector< int> & data) //bubble sort
(
int count = ();
int tag = false ; //设置是否需要继续冒泡的标志位
for ( int i = 0 ; i < count ; i+ +)