여기서 우리는 구조체 변수에 대해 어떤 유형의 연산을 수행할 수 있는지 볼 것입니다. 여기서는 기본적으로 struct에 대해 하나의 작업을 수행할 수 있습니다. 작업은 할당 작업입니다. 같음 검사 또는 기타와 같은 일부 다른 작업은 스택에 사용할 수 없습니다.
예시
#include <stdio.h>
typedef struct { //define a structure for complex objects
int real, imag;
}complex;
void displayComplex(complex c){
printf("(%d + %di)\n", c.real, c.imag);
}
main() {
complex c1 = {5, 2};
complex c2 = {8, 6};
printf("Complex numbers are:\n");
displayComplex(c1);
displayComplex(c2);
} 출력
Complex numbers are: (5 + 2i) (8 + 6i)
이것은 구조체에 일부 값을 할당했기 때문에 잘 작동합니다. 이제 두 개의 구조체 개체를 비교하려면 차이점을 살펴보겠습니다.
예시
#include <stdio.h>
typedef struct { //define a structure for complex objects
int real, imag;
}complex;
void displayComplex(complex c){
printf("(%d + %di)\n", c.real, c.imag);
}
main() {
complex c1 = {5, 2};
complex c2 = c1;
printf("Complex numbers are:\n");
displayComplex(c1);
displayComplex(c2);
if(c1 == c2){
printf("Complex numbers are same.");
} else {
printf("Complex numbers are not same.");
}
} 출력
[Error] invalid operands to binary == (have 'complex' and 'complex')