/* C No Evil Homework Each question carries equal weight. The assignment must be turned in and committed to your SVN by August 31, 2011 at 11:00am. No late submissions will be allowed. Instructions on how to use SVN and other information relating to online submission can be found on the course website. http://www.cs.illinois.edu/class/cs241/handin.html */ /* Part I Each of these examples can appear inside C programs. The ... means additional (irrelevant) instructions. For each example, answer the following questions: (a) What does the code attempt to do? (b) Correct the code listed */ /*Goal: Insert description of intended functionality here */ void Problem1(){ int x; int *p = x; } /*Goal: Insert description of intended functionality here */ void Problem2(){ float *p; *p = 12.5 } /*Goal: Insert description of intended functionality here */ void Problem3(){ float a; ... if(0 < a < 1) printf("a is a value between 0 and 1.\n"); } /*Goal: Insert description of intended functionality here */ void Problem4(){ int x=5; int y; ... if(x=y) printf("x and y are equal.\n"); else printf("x and y are different.\n"); } /*Goal: Insert description of intended functionality here */ void Problem5(){ int x, *ip; float y, *fp; ... ip = &x; fp = (float*)ip; y=*fp; } /*Goal: Insert description of intended functionality here */ void Problem6(){ int a=0, b=10; while (a =! b){ ... a++; } } /*Goal: Insert description of intended functionality here */ void Problem7(){ char s[30]; scanf("%30s",s); s[30] = '\0'; } /*Goal: Insert description of intended functionality here */ //Problem 8 void reset(int *x){ x=0; } int main(){ ... int x=1; reset(&x); printf("x is now 0.\n"); return 0; } /*Goal: Insert description of intended functionality here */ void Problem9(){ char *s = (char *) malloc (50); ... s="this is a string"; free(s); } /*Goal: Insert description of intended functionality here */ void Problem10(){ float *values; int i,n = 10; for(i=0;i> << ! + = For Example: value=0xFF flag=0x55 -> retval=0xAA */ } long int isEqual(long int x, long int y){ /* returns 1L if x==y, 0L otherwise using only the operators & ~ ^ | >> << ! + = */ }