阿尔卡特朗讯笔试题

 1. 如何打印出当前源文件的文件名以及源文件的当前行号

阿尔卡特朗讯笔试题

 通常使用的就是__FILE__, __LINE__,在调试函数中利用“%s”,”%ld”,打印就好了。

2. main主函数执行完毕后,是否可能会再执行一段代码,给出说明?
crt会执行另一些代码,进行处理工作。
如果你需要加入一段在main退出后执行的`代码,可以使用atexit()函数,注册一个函数。
语法:
#include <stdlib.h>
int atexit(void (*function”)(void));
#include <stdlib.h>
#include <stdio.h>

void fn1( void ), fn2( void ), fn3( void ), fn4( void );

int main( void )
{
atexit( fn1 );
atexit( fn2 );
atexit( fn3 );
atexit( fn4 );
printf( “This is executed first.n” );
}

void fn1()
{
printf( “next.n” );
}

void fn2()
{
printf( “executed ” );
}

void fn3()
{
printf( “is ” );
}

void fn4()
{
printf( “This ” );
}

3. 如何判断一段程序是由C编译程序还是由C++编译程序编译的?

c++编译时定义了 __cplusplus
c编译时定义了 _STDC_

4. 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.

参考答案
方案一

int max = ((a+b)+abs(a-b)) / 2

方案二

int c = a -b;
char *strs[2] = {“a大”,”b大”};
c = unsigned(c) >> (sizeof(int) * 8 – 1);