Joke Collection Website - Public benefit messages - Please help answer the questions in Tencent’s JAVA written test.

Please help answer the questions in Tencent’s JAVA written test.

1. Please define a macro to compare the size of two numbers a and b. You cannot use greater than, less than, or if statements

Answer:

#define max(a, b) ((((long)((a)-(b)))amp; 0x80000000)?b: a)

If a gt; b, then the highest binary bit of a-b is 0, and any number above is still 0, so the large number is a;

Otherwise, a-b is a negative number, the highest binary bit is 1, and the upper 0x80000000 (the highest bit is 1 and the others are 0) is 1 ,

So the largest number at this time is b.

2. How to output the title of the source file and the number of lines currently executed?

Answer: printf("The file name: d\n", __FILE__);

printf("The current line No: d\n", __LINE__);

ANSI C standard predefined macros:

__LINE__

__FILE__

__DATE__

__TIME__

__STDC__ This identifier is assigned a value of 1 when the program is required to strictly follow the ANSI C standard

__cplusplus__ This identifier is defined when writing a C program

3. No

4.while(1)

{

int *p = new int[10000];

}

5. Answer: A amp; B --gt; 2 mins

1 mins lt; -- A

C amp; D --gt; 10 mins

2 mins lt;-- B

A amp; B --gt; 2 mins

一*** 2 + 1 + 10 + 2 + 2 = 17 mins >

Hope this helps.