The following code fragment will be used for the following three questions int

# The following code fragment will be used for the

• Test Prep
• 7
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 4 - 7 out of 7 pages.

The following code fragment will be used for the following three questions: int data = {10, 4, 70}; int *m = data, *p; m++; p = m + 2; 11.(5 pts) What is the output of the following statement based on the above code: printf("%d %d %ld\n", *m, *p, p - data); 12.(5 pts) What would happen if we add the following statement after p = m + 2 above? 13.(5 pts) What would happen if we add the following statement after p = m + 2 above?printf("%ld", p + data); 14.(5 pts) What is the output of the following program? 5 15.(5 pts) What is the output of the following program if we execute it as follows: a.out 10 int main(int argc, char *argv[]) { printf("%d\n", argc); printf("%s\n", argv); printf("%s\n", argv); return 0; } 20 16.(5 pts) Identify the compilation problems that exists in the main() function below:#include <stdio.h> typedef struct student { const char *name; int age; } Student; int main(int argc, char *argv[]) { Student data[] = { {"Sally", 30}, {"Joe", 45} }; Student *p = &data; printf("%s\n", data.name); printf("%s\n", p.name); if (data != data) printf("Different\n"); data = data; printf("%s\n", data); return 0; } 6 Problem #2 (40 pts) 1.(15 pts) Implement an equalfunction that compares two integers returning 1 if they are equal and 0 otherwise. For this function the only allowed operators are + & | ~ ^ << ! >> only allowed constants are 1 2 4 8 16. Using invalid operators or constants will result in losing significant credit. int equal(int a, int b) { and the  • • • 