Class 7 Exam  >  Class 7 Questions  >  What will be the output of the following C++ ... Start Learning for Free
What will be the output of the following C++ code?
    #include <iostream>
    using namespace std;
    struct sec 
    {
        int a;
        char b;
    };
    int main()
    {
        struct sec s ={25,50};
        struct sec *ps =(struct sec *)&s;
        cout << ps->a << ps->b;
        return 0;
    }
  • a)
    252
  • b)
    253
  • c)
    254
  • d)
    262
Correct answer is option 'A'. Can you explain this answer?
Most Upvoted Answer
What will be the output of the following C++ code? #include <iostr...
Explanation:

Code Analysis:
- The code defines a structure `sec` with two members: `a` of type `int` and `b` of type `char`.
- In the `main` function, an object `s` of type `sec` is created and initialized with values 25 and 50 for members `a` and `b` respectively.
- A pointer `ps` of type `sec*` is created and assigned the address of object `s`.

Output Explanation:
- When `ps->a` is printed, it will output the value of member `a` of the object pointed to by `ps`, which is 25.
- When `ps->b` is printed, it will output the value of member `b` of the object pointed to by `ps`, which is 50.
Therefore, the output of the code will be `25 50`, which corresponds to option 'A'.
Free Test
Community Answer
What will be the output of the following C++ code? #include <iostr...
In this program, We are dividing the values of a and b, printing it.
Output:
$ g++ stu5.cpp
$ a.out
252
Explore Courses for Class 7 exam
Question Description
What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }a)252b)253c)254d)262Correct answer is option 'A'. Can you explain this answer? for Class 7 2025 is part of Class 7 preparation. The Question and answers have been prepared according to the Class 7 exam syllabus. Information about What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }a)252b)253c)254d)262Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Class 7 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }a)252b)253c)254d)262Correct answer is option 'A'. Can you explain this answer?.
Solutions for What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }a)252b)253c)254d)262Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Class 7. Download more important topics, notes, lectures and mock test series for Class 7 Exam by signing up for free.
Here you can find the meaning of What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }a)252b)253c)254d)262Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }a)252b)253c)254d)262Correct answer is option 'A'. Can you explain this answer?, a detailed solution for What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }a)252b)253c)254d)262Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }a)252b)253c)254d)262Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }a)252b)253c)254d)262Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Class 7 tests.
Explore Courses for Class 7 exam

Top Courses for Class 7

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev