1, [CPP] view plain copy int A; #define M (x,y) (x/y) A = m (4+2, 3) a=?
This is the knowledge of macro definitions, and the definition of macros is simply substitution.
The expansion of M (4+2, 3) is 4+2/3.
So a=4.
The following two examples may help to better understand:
#define m (x) x*x* (x+1)
int a=2,b=3;
The result of M (a+b) is 26
The expansion of M (a+b) is a+b*a+b* (a+b+1), the result is 26
#define m (x) (x) * (x) * (x+1)
int a=2,b=3;
The result of M (a+b) is 150
The M (a+b) expansion is (a+b) * (a+b) * (a+b+1) The result is 5*5*6=150
2. [CPP] view plain copy int f (int x) {static int k = 0; x + + k++; return x; } int i; i = f (3) *f (2); i =?
K is a static variable that acts as a global variable, but it is defined within a function, externally invisible, and not visible as a global static variable.
So after the execution of F (3), the k=1, then the F (2), the value of K or 1, after the execution of F (2), k=2.
The final answer is 9.
3, in the x86,32-bit environment, the following program output results. [CPP] view plain copy double darrary[2] = {4, 8}, *p, *q; p = &dArrary[0]; Q = p+1; cout<<q-p<<endl; cout<< (int) q (int) p<<endl;
This topic examines the pointer type and the addition and subtraction of pointers. This problem needs to be performed under Visual Studio to make no error
P,q is the pointer, that is, the pointer variable, their type is double*, so their step in memory is 8
Q-p represents the number of element differences, casting to the address (int) q (int) P means subtracting the address values of two elements.
The final answer is 1 and 8.
4, calculate the following sizeof value. [CPP] view plain copy char str[] = "http://www.tendyron.com/"; char *p = str; int n = 10; sizeof (str) = sizeof (p) = 4 sizeof (n) = 4 void Foo (char str[100]) {sizeof (str) = 4; void *p = malloc (100); sizeof (p) = 4;
Because Foo is just a function, all passes are the first address of an array.
On a 32-bit machine, whatever pointers are 4 bytes, including the void * type.
5, what the following program outputs. [CPP] view plain copy void foo (char **p, int num) { *p = (char *) malloc (num); } Void test (void) { char *str = NULL; foo (&str,100); strcpy (str, "Hello"); printf ("%s", str); }
Output hello.
6, the following program output what. [CPP] view plain copy void Test (void) {char *str = (char *) malloc (100); strcpy (str, "World"); Free (str); if (str!= NULL) {strcpy (str, "World"); printf ("%s", str); } }
You must manually set STR to NULL after free (str), otherwise it does not point to null.
Free (str); The pointing memory is freed, and STR is not NULL, but a random number, commonly known as a wild pointer.
The free function simply changes a particular flag in the memory block that the malloc is applying to, and does not immediately empty the data in the block. Whether the release of this memory is the operating system to determine its own, and whether the release will be the memory block chain adjustment, so that the memory fragmentation reduction, are used by the operating system itself.
Output world.
7, the following program output results. [CPP] view plain copy char *getmemory () {char p[] = "Hello World"; return p; This returns the wrong} char *str = NULL; str = GetMemory (); printf ("%s", str); In the function of the life of this character array p is a local variable, can not be used to return, so the output is a garbled.
8. What is the problem with the following program [CPP] view plain copy char *_strcpy (const char *strsrc) {static char str[260]; strcpy (str, STRSRC); return str; This question I said is not good, has the meeting can explain.
9, two cycles in priority [CPP] view plain copy for (int i = 0; i < n; i + +) { if (condition) DoSomething (); else Doothersomething (); } if (condition) { for (int i = 0; i < n; i++) DoSomething (); } else { for (int i = 0; i < n; i++) doothersomething (); }
10, the simple answer to Windows platform Dynamic Link library two ways, as well as the difference between static and dynamic library.
11, known linked table node Head, write a function of this linked list in reverse order, the structure is as follows [CPP] view Plain copy strcut Node {int data; Node *next}; typedef struct node node;
12, on the 32-bit system, the program will be 16 into the string, such as "FE1234" into a long integer type.
13. Write a function Isbigendian to determine whether the byte storage order of the computer is ascending or descending.
14, 28 people buy water, 3 empty bottles can change a bottle of water, please buy at least how many bottles of water.
15. The professor selected two from the 2 to 9 figures, put and tell a, the product tells B, they take turns to guess this number, a said: I guess, B said: I can not guess, a said: I guessed, B said: I guess. What are these two numbers, please?
-------------------------------Analysis Process-------------------------------------
First step a said: "I guess not" the combination of proof and is not unique: meet the conditions of the and:
[15] 6+9,7+8
[8] 2+6,3+5
[7] 2+5,3+4
[14] 5+9,6+8
[10] 2+8,3+7,4+6
[9] 2+7,3+6,4+5
[12] 3+9,4+8,5+7
[13] 4+9,5+8,6+7
[11] 2+9,3+8,4+7,5+6
Second Step B said: "I guess not" the combination of the proof product is not unique, satisfies the condition the product:
[3x8,4x6]
[2x9,3x6]
[2x6,3x4]
The third step a said: "I guessed" there are several situations:
2+6=8 2*6=12 (and for the 8 situation, meet the second step)
3+5=8 3*5=15 (and for the 8 situation, not satisfied with the second step)
2+5=7 2*6=10 (and for the 7 situation, not satisfied with the second step)
3+4=7 3*4=12 (and for the 7 situation, meet the second step)
2+8=10 2+8=16 (and for the 10 situation, not satisfied with the second step)
3+7=10 3+7=21 (and for the 10 situation, not satisfied with the second step)
4+6=10 4+6=24 (and for the 10 situation, meet the second step)
2+7=9 2*7=14 (and for the 9 situation, not satisfied with the second step)
3+6=9 3*6=18 (and for the 9 situation, meet the second step)
4+5=9 4*5=20 (and for the 9 situation, not satisfied with the second step)
7+8=15 7*8=56 (and for the case of 15, does not meet the second step)
6+9=15 6*9=54 (and for the 15 situation, not satisfied with the second step)
and conditions for other values are similar to those of the 15.
The third step a said: "I guessed." The proof combination may be: 2-6 3-4 4-6 3-6
Fourth Step B said: "I guessed that" there are the following:
If 12, the combination may be 2-6, 3-4, 2-6,3-4 combination of the case of the third step is possible, so is B in the fourth step can not guess
If 18, the combination may be 2-9, 3-6, 2-9 combination of the case of the third step is not possible, 3-6 combination of the case of the third step is possible, so B in the fourth step can determine 3-6 is the only possible, that is sufficient necessary conditions, so said guessed.
If 24, the combination may be 3-8, 4-6, 3-8 combination of the case of the third step is not possible, 4-6 combination of the case of the third step is possible, so B in the fourth step can determine 4-6 is the only possible, that is sufficient necessary conditions, so said guessed.
Fourth Step B said: "I guessed." The proof combination may be one of 3-6 (and 9, product 18) 4-6 (and 10, product 24).
Final answer 3-6 or 4-6