CC++面试笔试题目集锦
一、输入一个n然后在屏幕上打印出NxN的矩阵! 例如,输入一个笔试差1分面试追几分3
123
894 765
输入一个4, 1234
1213145 1116156
10987
参考答案:
ttinclude
^include
#defineN10
voidprintCube(inta[][N], intn): voidmain ()
{
inta[N][N], n;
printf ( “inputn:\n”);
scanf ( “%d”,n );
printCu be (a[0], n): ge tch();
vo idpr intCube (in ta[] [N], in tn)
{
inti, j, round=l:
i ntm=l:
for (i =0;i
a[0 ]=m++;
for (i=n_l ; i=n/2;i -)
{
for (j=ro u nd; ja[j]=m ++; for(j=i;j=round;j -) a[j-l]=m++;
for (j =i; j>round : j -)
a[j~l ] [round-l]=m++;
for(j=round;j
a[round][j]=m ++;
round ++;
for(i=0;i
f or (j=0;j
pri ntf ( “%3d” , a [j ]);
printf ( “\n”);
二、    朗讯面试题:
T he rearetwo int variabl es:a andb, d on’ tu se “if ’’,“sw itch” or oth erjudgem en tstatemen t s, findoutt hebiggeston eofthetwonu mbers.
参考答案:
方案一in tmax = ((a+b ) +abs (a-b) )/2 方案二int c=a_b;
c har*strs[2 ]:{ “a ,” b 大,’ }; c=uns i gned(c) >> (s izeof (in t)*8 - 1):
三、    朗讯面试题:
如何打印出当前源文件的文件名以及源文件的当前行 号?
参考答案:通常使用的就是_?11^__1. INE_,在调 试函数中利用” s1 d,打印就
好了。
四、    朗讯面试题:
mai n主函数执行完毕后,是否可能会再执行一段代码, 给出说明?
参考答案:crt会执行另一些代码,进行处理工作。
如果你需要加入一段在main退出后执行的代码,可以 使用atexitO函数,注册一个函数。
语法:
#inclu de
intatex i t (void (fu nction”)(vo id)):
#inclu de
ttinclud e
voidfn 1 (vo id), fn 2 (voi d), fn 3 (void ), fn 4 (void): i ntmain(vo i d)
{
atexit(fnl);
atexi t (fn2);
at exi t (fn3);
atex it (fn 4);
p rin tf ( “This is executedf i rst. \n”);
}
voidfnl ()
{
p rintf ( “ne xt . \n”);
void fn2 () print f ( ‘‘e xecuted ’’); voidfn3 () printf ( “is”);
void f n4 ()
{
pri ntf ( “This”);
}
五、朗讯面试题:
如何判断一段程序是由c编译程序还是由C++编译程序 编译的?
参考答案:C++编译时定义了__cplusplus c编译时定义了_S TDC_
六、下面这道面试题怎么做(指针)tfincliide main() {
intc[3] [3] = {1,2, 3, 4, 5, 6, 7, 8, 9 };
for(i nt i=0; ifor (in tj=0; jp rint f ( “%ld \n”,c
[j]);
prin tf (“    \n”);