1、 c5 = c4 = analysis;+c4;c3 = &analysis6;c2 = c5 + 2 ;c1 = &analysis7 - 3 ;printf (%ct%ct%ct%ct%c, *c1,*c2,*c3,*c4,*c5);return 0; c1, c2, c3, c4 and c5 are pointers (which can hold addresses). analysis is an array variable which is holding the string analysis. The starting address of the array is giv
2、en to c5 and c4. Hence they point to first character in the array. c4 is incremented by 1. Hence points to c3 is given the address of 7th character (count from 0) of the array. Hence c3 points to character c5 points to first character. plus 2 means, c2 points to 3rd character (second in the string).
3、 c1 points to 3rd character from the end (not counting the last character). c1 holds the address. *c1 means the data strored at c1. Since c1 points to 3rd character from the end (that is 5th character - count starts from 0), *c holds character Hence *c1 will print on the screen. Similarly for other
4、pointer variables *c2, *c3, *c4 and *c53.a=5 b=10 c=7(ac)?a:(bb:c)Answer: 104Question : How do you declare an array of N pointers to functions returningpointers to functions returning pointers to characters?A. char *(*(*aN)()();B. Build the declaration up incrementally, using typedefs:C. Use the cde
5、cl program, which turns English into C and viceversa:D. All of the above.Answer : D5void main()int count=10,*temp,sum=0;temp=&count;*temp=20;sum;*temp=count;printf(%d %d %d ,count,*temp,sum); Answer : 20;6int i=7;%d,i+*i+); 49. Note: Dont change a variable twice in one expression.7 The number of syn
6、tax errors in the program?int f()f(1);f(1,2);f(1,2,3);f(int i,int j,int k)%d %d %d,i,j,k); None.8 void main()float j;j=1000*1000;%f,j);A. 1000000B. OverflowC. ErrorD. None of the above9 Give the output of the programunsigned i=1; /* unsigned char k= -1 = k=255; */signed j=-1; /* char k= -1 = k=65535
7、 */* unsigned or signed int k= -1 =k=65535 */if(igreaterif(i=j)equal less10Give the output of the programchar *s=12345sn;,sizeof(s); 411int i;for(i=1;i (1,2)B. *g(1,2)C. (*g)(1,2)D. g(1,2) C13 Can you have constant volatile variable?YES. We can have a const volatile variable.a volatile variable is a
8、 variable which can be changed by the extrenal events (like an interrput timers will increment the voltile varible. If you dont want you volatile varibale to be changed then declare them as “const volatile”.14.study the code:#includeconst int a=100;int *p;p=&a;(*p)+;a=%dn(*p)=%dn,a,*p);What is print
9、ed?A)100,101 B)100,100 C)101,101 D)None of the aboveAnswer CEmbedded C 1. Using the #define statement, how would you declare a manifest constant that returns the number of seconds in a year? Disregard leap years in your answer. #define SECONDS_PER_YEAR (60 * 60 * 24 * 365)ULIm looking for several th
10、ings here:Basic knowledge of the #define syntax (for example, no semi-colon at the end, the need to parenthesize, and so on) An understanding that the pre-processor will evaluate constant expressions for you. Thus, it is clearer, and penalty-free, to spell out how you are calculating the number of s
11、econds in a year, rather than actually doing the calculation yourself A realization that the expression will overflow an integer argument on a 16-bit machine-hence the need for the L, telling the compiler to treat the variable as a Long As a bonus, if you modified the expression with a UL (indicatin
12、g unsigned long), then you are off to a great start. And remember, first impressions count!2. Write the standard MIN macro-that is, a macro that takes two arguments and returns the smaller of the two arguments. #define MIN(A,B) (A)= (B) ? (A) : (B)The purpose of this question is to test the followin
13、g:Basic knowledge of the #define directive as used in macros. This is important because until the inline operator becomes part of standard C, macros are the only portable way of generating inline code. Inline code is often necessary in embedded systems in order to achieve the required performance le
14、vel Knowledge of the ternary conditional operator. This operator exists in C because it allows the compiler to produce more optimal code than an if-then-else sequence. Given that performance is normally an issue in embedded systems, knowledge and use of this construct is important Understanding of t
15、he need to very carefully parenthesize arguments to macros I also use this question to start a discussion on the side effects of macros, for example, what happens when you write code such as:least = MIN(*p+, b);3. Infinite loops often arise in embedded systems. How does you code an infinite loop in
16、C?There are several solutions to this question. My preferred solution is:while(1)?5. Using the variable a, give definitions for the following:a) An integer b) A pointer to an integer c) A pointer to a pointer to an integer d) An array of 10 integers e) An array of 10 pointers to integers f) A pointe
17、r to an array of 10 integers g) A pointer to a function that takes an integer as an argument and returns an integer h) An array of ten pointers to functions that take an integer argument and return an integer Answers :a) int a; / An integer b) int *a; / A pointer to an integer c) int *a; / A pointer
18、 to a pointer to an integer d) int a10; / An array of 10 integers e) int *a10; / An array of 10 pointers to integers f) int (*a)10; / A pointer to an array of 10 integers g) int (*a)(int); / A pointer to a function a that takes an integer argument and returns an integer h) int (*a10)(int); / An arra
19、y of 10 pointers to functions that take an integer argument and return an integer People often claim that a couple of these are the sorts of thing that one looks up in textbooks-and I agree. While writing this article, I consulted textbooks to ensure the syntax was correct. However, I expect to be a
20、sked this question (or something close to it) when Im being interviewed. Consequently, I make sure I know the answers, at least for the few hours of the interview. Candidates who dont know all the answers (or at least most of them) are simply unprepared for the interview. If they cant be prepared fo
21、r the interview, what will they be prepared for?6. What are the uses of the keyword static?Static has three distinct uses in C:A variable declared static within the body of a function maintains its value between function invocations A variable declared static within a module, (but outside the body o
22、f a function) is accessible by all functions within that module. It is not accessible by functions within any other module. That is, it is a localized global Functions declared static within a module may only be called by other functions within that module. That is, the scope of the function is loca
23、lized to the module within which it is declared Most candidates get the first part correct. A reasonable number get the second part correct, while a pitiful number understand the third answer. This is a serious weakness in a candidate, since he obviously doesnt understand the importance and benefits
24、 of localizing the scope of both data and code. 7. What do the following declarations mean?const int a;int const a;const int *a;int * const a;int const * const a ;Answer The first two mean the same thing, namely a is a const (read-only) integer. The third means a is a pointer to a const integer (tha
25、t is, the integer isnt modifiable, but the pointer is). The fourth declares a to be a const pointer to an integer (that is, the integer pointed to by a is modifiable, but the pointer is not). The final declaration declares a to be a const pointer to a const integer (that is, neither the integer poin
26、ted to by a, nor the pointer itself may be modified). 8. What does the keyword volatile mean? Give three different examples of its use. A volatile variable is one that can change unexpectedly. Consequently, the compiler can make no assumptions about the value of the variable. In particular, the opti
27、mizer must be careful to reload the variable every time it is used instead of holding a copy in a register. Examples of volatile variables are:Hardware registers in peripherals (for example, status registers) Non-automatic variables referenced within an interrupt service routine Variables shared by multiple tasks in a multi-threaded application 9.Can a pointer be volatile ? Explain. Yes, although this is not very common. An example is
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1