Multiple choice technology programming languages

A ( hypothetical ;) ) graphics program uses the following structure to represet a 3d point struct point3d { int x; int y; int z; // X,y,z represent the three cooddinates of a 3d point in space }; A function was written to calculate the distace between two point3d objects. void func(point3d pt1,point3d pt2) { // Calculate the distance ..... } say at run time 2 million point3d struct objects were created and the above mentioned function was called say 1 million times. Calling the above mentioned function will result in a performance hit because

  1. The point3d is represented as struct . change it to a class and it will run better

  2. The point3d struct is not byte aligned.

  3. The in the function point3d struct parameters are passed by value, Which will cause additional overhead.

  4. The point3d struct has 3 members of type int . Change it to short ,the program will run faster.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The function passes point3d structs by value, meaning the entire struct (12 bytes for 3 ints) is copied for each parameter, every time the function is called. With 2 million objects and 1 million function calls, this results in copying 24 million bytes (2 parameters x 12 bytes x 1 million calls) - a significant performance overhead. Passing by reference (const point3d&) would avoid this copying.