cs 241 data organization quiz 5
play

CS 241 Data Organization Quiz 5 March 8, 2018 Question 1: - PowerPoint PPT Presentation

CS 241 Data Organization Quiz 5 March 8, 2018 Question 1: Structures and Functions struct Point {int x; int y;}; struct Point incPoint(struct Point p) { p.x++; p.y++; A p1=(4, 3) p2=(5, 4) return p; B p1=(4, 3) p2=(4, 3) } int


  1. CS 241 Data Organization Quiz 5 March 8, 2018

  2. Question 1: Structures and Functions struct Point {int x; int y;}; struct Point incPoint(struct Point p) { p.x++; p.y++; A p1=(4, 3) p2=(5, 4) return p; B p1=(4, 3) p2=(4, 3) } int main(void) C p1=(5, 4) p2=(4, 3) { D p1=(5, 4) p2=(5, 4) struct Point p1 = {4, 3}; struct Point p2 = incPoint(p1); E The value in p2 is printf("p1 =(\%d, \%d) unpredictable. p2 =(\%d, \%d)\n", p1.x, p1.y, p2.x, p2.y); }

  3. Question 1: Structures and Functions struct Point {int x; int y;}; struct Point incPoint(struct Point p) { p.x++; p.y++; A p1=(4, 3) p2=(5, 4) return p; B p1=(4, 3) p2=(4, 3) } int main(void) C p1=(5, 4) p2=(4, 3) { D p1=(5, 4) p2=(5, 4) struct Point p1 = {4, 3}; struct Point p2 = incPoint(p1); E The value in p2 is printf("p1 =(\%d, \%d) unpredictable. p2 =(\%d, \%d)\n", p1.x, p1.y, p2.x, p2.y); }

  4. Question 2: Pointer and Index int main(void) { char data [] = "computer science"; data [12] = ’*’; char *linePt = \& data [4]; *linePt = ’+’; printf("[\%s], [\%s]\n", data , linePt ); return 0; } A [computer science], [computer science] B [comp+ter sci*nce], [comp+ter sci*nce] C [comp+ter science], [computer sci*nce] D [comp+ter sci*nce], [uter sci*nce] E [comp+ter sci*nce], [+ter sci*nce]

  5. Question 2: Pointer and Index int main(void) { char data [] = "computer science"; data [12] = ’*’; char *linePt = \& data [4]; *linePt = ’+’; printf("[\%s], [\%s]\n", data , linePt ); return 0; } A [computer science], [computer science] B [comp+ter sci*nce], [comp+ter sci*nce] C [comp+ter science], [computer sci*nce] D [comp+ter sci*nce], [uter sci*nce] E [comp+ter sci*nce], [+ter sci*nce]

  6. Question 3: Pointers to Structures struct Point {int x; int y;}; void incrementPoint(struct Point *p) { A p1=(3, 3) (*p).x += 2; p->y += 2; B p1=(1, 3) } C p1=(1, 1) int main(void) D p1=(3, 1) { struct Point p1 = {1, 1}; E p1 = 2 incrementPoint (&p1); printf("p1=(%d, %d)\n", p1.x, p1.y); return 0; }

  7. Question 3: Pointers to Structures struct Point {int x; int y;}; void incrementPoint(struct Point *p) { A p1=(3, 3) (*p).x += 2; p->y += 2; B p1=(1, 3) } C p1=(1, 1) int main(void) D p1=(3, 1) { struct Point p1 = {1, 1}; E p1 = 2 incrementPoint (&p1); printf("p1=(%d, %d)\n", p1.x, p1.y); return 0; }

  8. Question 4: Pointers to Structures #include <stdio.h> #include <math.h> struct Point {double x; double y;}; void foo(struct Point *p) A p1=( 5, 4) { double d = sqrt ((p->x)*(p->x) B p1=( 0.78, 0.62) + (p->y)*(p->y)); p->x /= d; C p1=( 5.00, 4.00) p->y /= d; } D p1=( 0.60, 0.80) void main(void) { E p1=( 0.12, 0.98) struct Point p1 = {5, 4}; foo (\&p1); printf("p1 =(%5.2f, %5.2f)\n", p1.x, p1.y); }

  9. Question 4: Pointers to Structures #include <stdio.h> #include <math.h> struct Point {double x; double y;}; void foo(struct Point *p) A p1=( 5, 4) { double d = sqrt ((p->x)*(p->x) B p1=( 0.78, 0.62) + (p->y)*(p->y)); p->x /= d; C p1=( 5.00, 4.00) p->y /= d; } D p1=( 0.60, 0.80) void main(void) { E p1=( 0.12, 0.98) struct Point p1 = {5, 4}; foo (\&p1); printf("p1 =(%5.2f, %5.2f)\n", p1.x, p1.y); }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend