For more information, see answers.
Question 1st: (B)
Volatile literally means volatile. When this keyword is used to describe a variable, it means that after the variable is assigned a value (written), it will be read immediately. The written value may be different from the read value, so it is "volatile.
This is because this variable may be a register that is directly connected to an external device. After you write it, the register may also be changed by the write operation of the external device; or, this variable is interrupted by one program or another process
Changed.
Volatile will not be affected by Compiler Optimization. After longjump, its value is the variable value assumed later, and B's final value is 5, so 5 is printed.
Setjmp: set non-local jump/* setjmp. H */
Stores context information such as register values so that the lomgjmp function can return control to the statement following the one calling setjmp. returns 0 when it is initially called.
Lonjjmp: execute a non-local jump/* setjmp. H */
Transfers control to the statement where the call to setjmp (which initialized BUF) was made. execution continues at this point as if longjmp cannot return the value 0.a nonvolatile automation variable might be changed by a call to longjmp. when you use setjmp and longjmp, the only automatic variables guaranteed to remain valid are those declared volatile.
Note: test program without volatile qualifier (result may very)
For more information, see setjmp and longjmp in C.
2nd Question: ()
The addresses of the structure questions in the memory increase in sequence according to their defined locations. If a pointer to a struct is regarded as a pointer to its first member, the pointer does point to the first member.
3rd question: ()
This question is difficult.
Non-recursive version of this program
Int what (int x, int N)
{
Int val;
Int product;
Product = 1;
Val = X;
While (n> 0)
{
If (N % 2 = 1)
Product = product * val;/* if it is an odd power, x (VAL) must first multiply the previous power; if it is an even power, it will be multiplied by 1 */
Val = Val * val;
N = n/2;
}
Return product;
}/* Use a binary compound multiplication policy */
Algorithm Description
(While n> 0)
{
If next most significant binary digit of N (Power) is one
Then multiply accumulated product by current Val,
Reduce N (Power) sequence by a factor of two using integer division.
Get next Val by multiply current value of itself
}
4th question: (c)
A is an integer array with 5 members.
& A is a pointer to an integer array.
So where & A + 1 points is equivalent to a [6]
{
Function anonymous ()
{
If (this. width> 520) This. width = 520;
}
} "Style =" cursor: Hand "onclick =" javascript: window. open (this. SRC); "src =" http://www.myfavor.org/upload_files/2007/03/13/191940.jpg "onLoad =" javascript: If (this. width> 520) This. width = 520; "align =" absmiddle "border =" 0 ">
Therefore, * (a + 1) is equivalent to a [1].
PTR is equivalent to a [6], and ptr-1 is equivalent to a [5]
Question 5th: (B)
{
Function anonymous ()
{
If (this. width> 520) This. width = 520;
}
} "Style =" cursor: Hand "onclick =" javascript: window. open (this. SRC); "src =" http://www.myfavor.org/upload_files/2007/03/13/191945.jpg "width =" 520 "onLoad =" javascript: If (this. width> 520) This. width = 520; "align =" absmiddle "border =" 0 ">
The question itself gives enough tips
B [0] [0] = 4
B [1] [0] = 7
6th question: (c)
Test the comma expression. The priority of a comma expression is very low, which is lower than that of a value (=). The value of a comma expression is the value of the last element.
Another function of the comma expression is to split the parameter list of the function ..
E1, E2,..., en
In the preceding expression, the values of E1, E2,... en are calculated separately. The structure calculated by en is assigned to the entire comma expression.
C = A, B;/* yields c = */
D = (a, B);/* D = B */
7th question: ()
{
Function anonymous ()
{
If (this. width> 520) This. width = 520;
}
} "Style =" cursor: Hand "onclick =" javascript: window. open (this. SRC); "src =" http://www.myfavor.org/upload_files/2007/03/13/192207.jpg "onLoad =" javascript: If (this. width> 520) This. width = 520; "align =" absmiddle "border =" 0 ">
PTR is an array pointer, which has three int members.
8th question: (c)
Obviously there is a problem with F1. It returns a pointer to a local variable. The local variable is saved in the stack. After exiting the function, the local variable is destroyed and its pointer remains meaningless, because the stack space it points to may be overwritten by other variables
F2 also has a problem. PTR is a local variable and has not been initialized. Its value is unknown. * PTR does not know where it points. Directly assigning a value to * PTR may overwrite important system variables, this is a type of wild pointer.
Question 9th: (B)
The sizeof operator gives the space occupied by its operations. It can be determined during compilation. Therefore, its operations, even an expression, do not need to be calculated at runtime. (++ I) is not executed, so
The I value is 3.
10th question: ()
Apparently, select.
* P and q values are exchanged in F1. After F1 is executed, * p and q values are indeed exchanged, but Q changes do not affect B changes. * P is actually
Therefore, after F1 is executed, a = B = 5
This question covers a wide range of knowledge, including typedef custom types, function pointers, and pointer arrays.
Void (* P [2]) (int *, INT );
Array p that defines a function pointer. P has two pointer elements. an element is a function pointer. The function pointer points to a function with two parameters. The Void function is returned. The two parameters are pointer to an integer and integer.
P [0] = F1; P [1] = F2 contain address of function. function name without parenthesis represent address of function value and address of variable is passed to function only argument that is specified TED is a (address is passed ). because of call by value F1, F2 can not effect B
11th question: ()
{
Function anonymous ()
{
If (this. width> 520) This. width = 520;
}
} "Style =" cursor: Hand "onclick =" javascript: window. open (this. SRC); "src =" http://www.myfavor.org/upload_files/2007/03/13/192306.jpg "onLoad =" javascript: If (this. width> 520) This. width = 520; "align =" absmiddle "border =" 0 ">
Test-operation and recursive call. You can analyze it carefully.
12th question: (c)
Analysis Function declaration, it is recommended not to look at "C expert programming"
Here is a simple rule: From left to left, when a bracket is encountered, the content in the first bracket is regarded as a whole.
13th question: (c)
Check when the array is a pointer. for some types of T, if an expression is a T [] (T array), the value of this expression is actually a pointer to the first element of the array. so (BUF + 1) [5] is actually * (BUF + 6) or Buf [6]
Question 14th: (B)
{
Function anonymous ()
{
If (this. width> 520) This. width = 520;
}
} "Style =" cursor: Hand "onclick =" javascript: window. open (this. SRC); "src =" http://www.myfavor.org/upload_files/2007/03/13/192342.jpg "onLoad =" javascript: If (this. width> 520) This. width = 520; "align =" absmiddle "border =" 0 ">
The value of sizeof (INT) is 2, so P + = sizeof (INT) points to argv [2]. We have no doubt about this.
(P + = sizeof (INT) [-1] points to argv [1]. Can you understand it, because (p + = sizeof (INT )) [-1] is equivalent to (p + = 2) [-1], that is, (p + 2-1)
15th question: (c)
The C compiler usually provides a series of macros for processing variable parameters to shield the differences caused by different hardware platforms and increase program portability. These macros include va_start, va_arg, and va_end.
When the ANSI standard form is used, the prototype declaration of a function with a variable number of parameters is:
Type funcname (type para1, type para2 ,...)
This form requires at least one common form parameter, and the ellipsis behind it does not mean to be omitted, but is part of the function prototype. Type is the type of function return values and formal parameters.
Different compilers have different implementations for this variable length parameter. gcc4.x contains built-in functions.
For variable length parameters, see
Http://www.upsdn.net/html/2004-11/26.html
Http://www.upsdn.net/html/2004-11/26.html
Program Analysis
Va_list P;/* define a variable and save the pointer to the function parameter list */
Va_start (p, n);/* use the va_start macro to initialize the 2nd parameter n of the Variable P, va_start macro, which is a fixed parameter, it must be the last input stack parameter of our own variable-length function, that is, the 1st parameters in the parameter list during the call */
For (; j <n; ++ J)/* j traverses all variable parameters starting from 1 */
{
I = va_arg (p, INT);/* va_arg retrieves the current parameter and considers it to be an integer (INT )*/
For (; I; I & = i-1)/* determine whether the retrieved I is 0 */
+ + K;/* if I am not 0, K auto-increment, I perform logical operations with the I-1 until I is 0. This is a trick and I will talk about its function below */
}
When we call the ripple function, the first parameter n in the parameter list passed to the ripple function is 3.
Va_start initialize P. The morale points to the first unnamed parameter (N is a parameter with a name), that is, is 5 (the first parameter ).
Each call to va_arg returns a parameter and Points P to the next parameter.
Va_arg uses a type name to determine the type of the returned parameter, and in the internal implementation of var_arg, the distance to the next parameter is determined.
(; I; I & = i-1) K ++/* calculate how many bits I have been set to 1 */
5. In binary format, it is (101) 2.
7 In binary format (111) 3
Therefore, K returns 5 (2 + 3), that is, C should be selected.
For example, it is easy to understand.
Make I = 9 = 1001
I-1 = 1000
(I-1) + 1 = I
1000
+ 1
1 001
Because I and the I-1's rightmost (DIGIT) must be different, if i1, The I-1 must be 0, and vice versa. the I & I-1 operation removes the rightmost 1 bit in the binary complement numeric system
Question 16th: (B)
The answer is (B)
It is said that Gauss will do this sort of proportional series during the first grade of elementary school. this question examines the knowledge of static variables. After each function is called, the value of static variables will not be lost, which is significantly different from the temporary local variables in the stack.
Therefore, after counter (0) is called for the first time, Count = 0
Count = 0 + 1 after the second counter (1) call;
The third counter (2) Count = 1 + 2;/* COUNT = count + I */
The fourth counter (3) Count = 3 + 3;
The fifth counter (4) Count = 6 + 4 call;
The sixth counter (5) Count = 10 + 5 call;
Ashok. pathak a member (research staff) at Bharat Electronics Limited (CRL), Ghaziabad. he has been developing embedded application for the past five years. ashok holds a M. E in computer science and engineering. ashok recently completed a book about' "advanced test in C and embedded system programming", published by BPB, nd.