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

The following code fragment will be used for the

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

The following code fragment will be used for the following three questions: int data[5] = {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?
Background image
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[0]); printf("%s\n", argv[1]); 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[0]; printf("%s\n", data[0].name); printf("%s\n", p.name); if (data[0] != data[1]) printf("Different\n"); data[1] = data[0]; printf("%s\n", data[1]); return 0; }
Background image
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
Background image
Image of page 7

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture