We are doing access attributes of class and then modify it.
#include <iostream>
using namespace std;
class MyClass { // The class
public: // Public access specifier
int x; // Public attribute (int variable)
};
int main() {
MyClass myObj; // Create an object of MyClass
// Access attributes and set values
myObj.x = 15;
// Print values
cout << myObj.x;
return 0;
}
We are doing call an function with multiple times.
#include <iostream>
using namespace std;
void myFunction() {
cout << "I just got executed!\n";
}
int main() {
myFunction();
myFunction();
myFunction();
return 0;
}
We are doing compare two integers numbers and print result of its.
#include <iostream>
using namespace std;
int main() {
cout << (10 == 15);
return 0;
}
We are doing create an object of class then called constructor automatically
#include <iostream>
using namespace std;
class MyClass { // The class
public: // Access specifier
MyClass() { // Constructor
cout << "Hello World!";
}
};
int main() {
MyClass myObj; // Create an object of MyClass (this will call the constructor)
return 0;
}
we are doing print sum of two numbers with the help of addition operator.
#include <iostream>
using namespace std;
int main() {
int x = 100 + 50;
cout << x;
return 0;
}