Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
my question is declare variable x1, x2 and x3 as structure of type complex
may i know my below answer correct?

struct complex{
   struct complex *x1;
   struct complex *x2;
   struct complex *x2;
};
Posted

Uhm no, it's not.

Here's C code (not C++) :

C++
struct complex
{
    // struct members
    double realPart;
    double imaginaryPart;
};

void Foo()
{
    struct complex x1;
    struct complex x2;
    struct complex x3;
}
 
Share this answer
 
v2
Comments
Jayfam 28-Apr-11 15:53pm    
the question just declare variable x1, x2 and x3 as structure of type complex , why your answer got int z ?
Nish Nishant 28-Apr-11 15:54pm    
In C (not C++) a struct must have at least 1 member.
Nish Nishant 28-Apr-11 15:55pm    
The int z was just an example. You would need to define members based on your scenario.
Nish Nishant 28-Apr-11 15:56pm    
Manfred has updated the code to make it more obvious.
Jayfam 28-Apr-11 16:02pm    
void Foo() mean?
no.
struct COMPLEX x1;
struct COMPLEX x2;
struct COMPLEX x3;

if...
C++
struct COMPLEX{
 double real;
 double imaginary;
};


or...
COMPLEX x1;
COMPLEX x2;
COMPLEX x3;

if...
typedef struct _COMPLEX_{
 double real;
 double imaginary;
} COMPLEX;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900