Construct complex Objects

You can use the complex constructor to construct initialized or uninitialized complex objects or arrays of complex objects. The following example shows different ways of creating and initializing complex objects:

   complex comp1;                  // Initialized to (0, 0)
   complex comp2(3.14);            // Initialized to (3.14, 0)
   complex comp3(3.14,2.72);       // Initialized to (3.14, 2.72)
   complex comparr1[3]={
      1.0,                         // Initialized to (1.0, 0)
      complex(2.0,-2.0),           //                (2.0, -2.0)
      3.0                          //                (3.0, 0)
      };
   complex comparr2[3]={
      complex(1.0,1.0),            // Initialized to (1.0, 1.0)
      2.0,                         // (2.0, 0)
      complex(3.0,-3.0)            // (3.0, -3.0)
      };
   complex comparr3[3]={
      1.0,                         // Initialized to (1.0, 0)
      complex(M_PI_4,M_SQRT2),     // (0.785..., 1.414...)
      M_SQRT1_2                    // (0.707..., 0)
      }; 

Related Concepts

Related Tasks