문제

Is it possible to assign value of one structure variable to another structure variable Is this code correct -

#include<iostream.h>
struct s1
{
    int a;
    float b;
    char c;
}   st1,st2,st3;
int main()
{
    struct s2{
            int x;
            float y;
            char z;
        }   ss1,ss2,ss3;
        // Read & Initialize structures 
        ss2=ss1;
        :
        ss3.z=st1.c;
           :
}
void func1()
{
    ss2.x=st1.a;
    ss3.y=st2.b;
    ss1.z=st3.c;
       :
    ss1=ss3;
}

Kindly clear my doubt whether the above code is OK or not

도움이 되었습니까?

해결책

ss2=ss1; this will depend on the compiler some compiler will allow to copy the structure variable and some not.
ss2.x=st1.a; ss2 structure will be local to the main function and it is not available in funct1(), so it must be throwing the compilation error.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top