hw8 - Homework 8 (Problems 3-10) 3. (Ch. 12, Problem 2)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework 8 (Problems 3-10) 3. (Ch. 12, Problem 2) Give the output of the following program. #include <stdio.h> struct tag{ Output: int i; s2.i = 20 char name[32]; s2.name = ABCD1234 } s1={10, "ABCD"}; int main() { struct tag s2; s2.i = 2*s1.i; strcpy(s2.name, s1.name); strcat(s2.name, "1234"); printf("s2.i = %d\n", s2.i); printf("s2.name = %s\n", s2.name); return 0; } 4. (Ch. 12, Problem 13) What does the following program print? #include <stdio.h> struct tag{ Output: char *p; s.p = abcd char name[32]; s.p[1] = b } s.name = ABCD s = {"abcd", "ABCD"}; s.name[0] = A s.name[1] = B int main() { *s.name = A printf("s.p = %s\n", s.p); printf("s.p[1] = %c\n", s.p[1]); printf("s.name = %s\n", s.name); printf("s.name[0] = %c\n", s.name[0]); printf("s.name[1] = %c\n", s.name[1]); printf("*s.name = %c\n", *s.name); return 0; } 5. (Ch. 12, Problem 14) Modify function averageGPA() in Program 12.10 using a pointer operator sp->, instead of using array reference s[i] , to access each element of the passed array. Modified code in function averageGPA():
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

hw8 - Homework 8 (Problems 3-10) 3. (Ch. 12, Problem 2)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online