I am studying for my final, which is tomorrow. It is an intro to C class and I have just a couple questions. He gave us this sample final and I don't get a couple of them and was seeing if someone could help me understand what is happening. Here goes...
Question #1: What is the output of the following code segment, assuming strcopy() works without problem?
The answer is "ifmmp" so I guess I don't understand what is hapenning in the while section, if anyone could explain that it would be great.Code:int main() { char data[10], *p; strcpy(date, "hello"); p = data; while (*p != '\0') *p++ += 1; printf("%s", data); return 0; }
Question #2:
What is the output of the following code segment?
I guess I don't get what is happening at the printf statement withCode:int foo[3][3]; int main(_ { int i, j; int *p; for (i=0; i<3; i++) for (j=0; j<3; j++) foo[i][j] = (i+1) * (j+1); p = foo; printf("%d", *(p+7)); return 0; }
*(p+7)...what does that do?
The answer according to him is 6.
Question #3:
What is the output of the following code segment?
His answer is 2, but I have no clue how he got it. I don't really get the printf statement, so if anyone does, please help.Code:struct list{ int data; struct list * next; }; int main() { struct list a, b, c; a.data = 3; b.data = 1; c.data = 2; a.next = &b; b.next = &c; printf("%d\n", a.next->next->data); return 0; }
Thanks in advance for anyone who helps me, I really appreciate it and so does my grade.



LinkBack URL
About LinkBacks


