Without Class Example:
#include <iostream.h>
char n = 'k'; // A global variable
int main() {
char n = 'g'; // A local variable
cout << ::n << endl; // Print the global variable: k
cout << n << endl; // Print the local variable: g
}
With Class Example
#include <iostream.h>
class gajjar {
public:
void output();
};
void gajjar::output() {
cout << "Outside the class.\n";
}
int main() {
gajjar x;
x.output();
return 0;
}
#include <iostream.h>
char n = 'k'; // A global variable
int main() {
char n = 'g'; // A local variable
cout << ::n << endl; // Print the global variable: k
cout << n << endl; // Print the local variable: g
}
With Class Example
#include <iostream.h>
class gajjar {
public:
void output();
};
void gajjar::output() {
cout << "Outside the class.\n";
}
int main() {
gajjar x;
x.output();
return 0;
}
No comments:
Post a Comment