• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C++ | Class and Object | Question 6

Which of the following is true about the following program CPP
#include <iostream>
class Test
{
public:
    int i;
    void get();
};
void Test::get()
{
    std::cout << \"Enter the value of i: \";
    std::cin >> i;
}
Test t;  // Global object
int main()
{
    Test t;  // local object
    t.get();
    std::cout << \"value of i in local t: \"<<t.i<<\'\\n\';
    ::t.get(); 
    std::cout << \"value of i in global t: \"<<::t.i<<\'\\n\';
    return 0;
}
Contributed by Pravasi Meet

(A)

Compiler Error: Cannot have two objects with same class name

(B)

Compiler Error in Line "::t.get();"

(C)

Compiles and runs fine

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments