Close
Close

Help me Figure out this if its Broken or just defunct or maybe im writin it all wrong.... Question was-Figure out the output of the following program

   Anthony Stark

#include <iostream>
int main()
{
    struct student
    {
        int roll;
        int age;
    };
    studentS1={100,15}
    studentS2=S1;
    if(S1==S2)
    std::cout<<"The structures are equal";
    else
    std::cout<<"The structures are not equal";
    }
}

THE ERROR -Compilation failed due to following errors-
 

main.cpp: In function 'int main()':main.cpp:17:5: error: 'studentS1' was not declared in this scope     studentS1={100,15}     ^main.cpp:19:8: error: 'S1' was not declared in this scope     if(S1==S2)        ^main.cpp:19:12: error: 'S2' was not declared in this scope     if(S1==S2)            ^main.cpp: At global scope:main.cpp:24:1: error: expected declaration before '}' token } ^

 


Answers

  •   

    The last bracket (}) should not be there.

    studentS1={100,15} → should be student S1={100,15};

    studentS2=S1; → should be student S2=S1;

    if(S1==S2) → This is wrong. You can’t compare two structures.


    • Thanks for the Answer bro my printsheet had print errors i think thanks a LOT.:)
      - Anthony Stark

  •    OSH UNIVERSITY

    Osh University sets the stage for your medical aspirations with its bachelor of medicine program. Dive into a world-class education that blends theoretical knowledge with hands-on experience, preparing you for the challenges of the ever-evolving medical landscape.



  •    shalamarhospital

    Shalamar Hospital is your trusted healthcare destination, offering the expertise of a renowned stomach specialist . Expect top-notch care for gastrointestinal health.



Ask Yours
Post Yours
Write your answer