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;
    int main()
    {
        int a = 5, b = 6, c, d;
        c = a, b;
        d = (a, b);
        cout << c << ' ' << d;
        return 0;
    }
  • a)
    5  6
  • b)
    6  5
  • c)
    6  7
  • d)
    6  8
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...
It is a separator here. In C, the value a is stored in c and in d the value b is stored in d because of the bracket.
Output:
$ g++ op3.cpp
$ a.out
5    6
Free Test
Community Answer
What will be the output of the following C++ code? #include <iostr...
Explanation:

Initialization:
- Two integer variables 'a' and 'b' are initialized with values 5 and 6 respectively.
- Two integer variables 'c' and 'd' are declared.

Assignment:
- In the statement 'c = a, b;' the value of 'a' is assigned to 'c' and then 'b' is discarded.
- In the statement 'd = (a, b);' the comma operator evaluates both 'a' and 'b', but only the value of 'b' is assigned to 'd'.

Output:
- The value of 'c' will be 5 (a value of 'a').
- The value of 'd' will be 6 (a value of 'b').
Therefore, the output of the code will be:
5 6
Explore Courses for Class 7 exam
Question Description
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a, b); cout << c << << d; return 0; }a)5  6b)6  5c)6  7d)6  8Correct 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; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a, b); cout << c << << d; return 0; }a)5  6b)6  5c)6  7d)6  8Correct 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; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a, b); cout << c << << d; return 0; }a)5  6b)6  5c)6  7d)6  8Correct 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; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a, b); cout << c << << d; return 0; }a)5  6b)6  5c)6  7d)6  8Correct 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; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a, b); cout << c << << d; return 0; }a)5  6b)6  5c)6  7d)6  8Correct 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; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a, b); cout << c << << d; return 0; }a)5  6b)6  5c)6  7d)6  8Correct 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; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a, b); cout << c << << d; return 0; }a)5  6b)6  5c)6  7d)6  8Correct 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; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a, b); cout << c << << d; return 0; }a)5  6b)6  5c)6  7d)6  8Correct 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; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a, b); cout << c << << d; return 0; }a)5  6b)6  5c)6  7d)6  8Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Class 7 tests.
Explore Courses for Class 7 exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev