/* CS 241: Homework #1 DUE DATE: On the SVN at 11:00am, Jan. 25, 2012 (No late submissions!) General Instructions: - This assignment is a SOLO assignment. - Each question is worth equal weight. - The assignment MUST be committed to your SVN by the due date. For instructions on how to use SVN and other course information relating to online submission, please see: http://www.cs.illinois.edu/class/cs241/handin.html [Part I] Each question consists of a C code snippet that contains one major problem. The problems range from compile-time errors, misuse of C functions or C syntax, and logical errors. In some questions, unnecessary code is eliminated and replaced with "...". For each problem, you must do two things: (a): State what the code attempts to do. (b): Correct the code. */ /* ===== Problem #1 ===== */ /*Goal: Insert description of intended functionality here */ void Problem1(){ int x; ... int *p = x; } /* ===== Problem #2 ===== */ /*Goal: Insert description of intended functionality here */ void Problem2(){ float *p; *p = 12.5 } /* ===== Problem #3 ===== */ /*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"); } /* ===== Problem #4 ===== */ /*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"); } /* ===== Problem #5 ===== */ /*Goal: Insert description of intended functionality here */ float Problem5(int x){ int *ip; float y, *fp; ... ip = &x; fp = (float*)ip; y=*fp; return y; } /* ===== Problem #6 ===== */ /*Goal: Insert description of intended functionality here */ void Problem6(){ int a=0, b=10; while (a =! b){ ... a++; } } /* ===== Problem #7 ===== */ /*Goal: Insert description of intended functionality here */ void Problem7(){ char s[30]; scanf("%30s",s); s[30] = '\0'; } /* ===== Problem #8 ===== */ /*Goal: Insert description of intended functionality here */ void reset(int *x){ x=0; } int main(){ ... int x=1; reset(&x); printf("x is now 0.\n"); return 0; } /* ===== Problem #9 ===== */ /*Goal: Insert description of intended functionality here */ void Problem9(){ char *s = (char *) malloc (50); ... s="this is a string"; free(s); } /* ===== Problem #10 ===== */ /*Goal: Insert description of intended functionality here */ void Problem10(){ float *values; int i,n = 10; for(i=0;i 0xAA Allowed Operators: & ~ ^ | >> << ! + = */ long int clear_bit(long int value, long int flag){ } /* ===== Problem #20 ===== */ /* Task: Return 1L if (x == y), otherwise return 0L. Allowed Operators: & ~ ^ | >> << ! + = */ long int is_equal(long int x, long int y){ }