资源预览内容
第1页 / 共19页
第2页 / 共19页
第3页 / 共19页
第4页 / 共19页
第5页 / 共19页
第6页 / 共19页
第7页 / 共19页
第8页 / 共19页
第9页 / 共19页
第10页 / 共19页
亲,该文档总共19页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Basic c question.1.Question:where in memory the variables are stored? Local variables, global variables, static. AnswerLocal variables sit in Stack. Global and static goto Data segment. Dynamic memory comes from Heap.2.Questioncan you explian the meaning for the follwoing programchar *c1, *c2, *c3, *c4, *c5 ; char analysis8 = a, n, a, l, y, s, i ,s; int main() 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; Answerc1, c2, c3, c4 and c5 are pointers (which can hold addresses). analysis is an array variable which is holding the string analysis. c5 = c4 = analysis; The starting address of the array is given to c5 and c4. Hence they point to first character a in the array. +c4; c4 is incremented by 1. Hence points to n in the array. c3 = &analysis6; c3 is given the address of 7th character (count from 0) of the array. Hence c3 points to character i. c2 = c5 + 2 ; c5 points to first character. plus 2 means, c2 points to 3rd character a (second a in the string). c1 = &analysis7 - 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 y. Hence *c1 will print y on the screen. Similarly for other pointer variables *c2, *c3, *c4 and *c53.Question:a=5 b=10 c=7(ac)?a:(bc)?b: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 cdecl program, which turns English into C and viceversa:D. All of the above. Answer : D5Question : void main()int count=10,*temp,sum=0;temp=&count;*temp=20;temp=∑*temp=count;printf(%d %d %d ,count,*temp,sum); Answer : 20; 20; 20;6Question : void main()int i=7;printf(%d,i+*i+); Answer : 49. Note: Dont change a variable twice in one expression.7Question : The number of syntax errors in the program?int f()void main()f(1);f(1,2);f(1,2,3);f(int i,int j,int k)printf(%d %d %d,i,j,k); Answer : None.8Question : void main()float j;j=1000*1000;printf(%f,j);A. 1000000B. OverflowC. ErrorD. None of the above Answer : D9Question : Give the output of the programvoid main()unsigned i=1; /* unsigned char k= -1 = k=255; */signed j=-1; /* char k= -1 = k=65535 */* unsigned or signed int k= -1 =k=65535 */if(ij)printf(greater);elseif(i=j)printf(equal); Answer : less10Give the output of the programvoid main()char *s=12345sn;printf(%d,sizeof(s); Answer : 411Question : Give the output of the programvoid main()int i;for(i=1;i (1,2)B. *g(1,2)C. (*g)(1,2)D. g(1,2) Answer : C13Question: Can you have constant volatile variable?Answer:YES. We can have a const volatile variable.a volatile variable is a 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.Question:study the code:#includevoid main()const int a=100;int *p;p=&a;(*p)+;printf(a=%dn(*p)=%dn,a,*p);What is printed?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. Answer#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)ULIm looking for several things 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 seconds 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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号