Lucent written test topic - C language section (ZZ)

xiaoxiao2021-03-06  44

Title: Lucent written test topic - C language part

Cannot perform other code after jumping out of the main () function

Do not use the third variable, interchange the two variables a, and B (no function)

How to determine whether a file is compiled by the C-compilation environment or C compilation environment?

Don't use any conditional statements to ask two maximum values? (No function)

Struct student {long ..; char .. float ..} How big is the space?

Here are some solutions, and you can learn from the new thing, Herf:

: You can do other code after jumping out of the main () function.

1) ATEXIT binding exit function

2) After the main execution is completed, can you perform other code?

Of course, the code of the .fini segment is finally executed,

If there is anything you need to do it through the entire program, you can put it in .fini paragraph

: Do not use the third variable, interchange the two variables A, and B (no function) 1. ) Xor (<=== different or ???)

2.) A = B;

B = a-b;

A = a-b;

3) Think of a very uncomfortable method

A * ((int) (b-a)) >> 31) b * ((int) (a-b)) >> 31) (<== to move 31 positions? It is too exaggerated

31 can be replaced with SizeOf (int) * 8-1

: How to determine whether a file is compiled by the C compilation environment?

When compiling, you can use the __cplusplus macro.

As for the completion of the completion, take the ELF file to determine, I can think of NM,

Look at there is no chain libstdc . But this is not insurance.

: Don't request the maximum number of shaping numbers without any conditional statement? (No function)

?: Is it calculated that the condition statement? :)

: struct student {long ..; char .. float ..} How big is the space?

1) Data Alignment and Padding

2) It should be 12

转载请注明原文地址:https://www.9cbs.com/read-79303.html

New Post(0)