The Code given below can be used in TURBO C++ Compilers: -
#include<iostream.h>
#include<conio.h>
class Student
{
public:
int id; // declaring members as public allowing us to modify them from outside the class
char *name;
};
void main()
{
clrscr();
Student s1;
s1.id = 2; // modifying id and name from outside the class
s1.name = "Abhishek";
cout << s1.id << endl;
cout << s1.name << endl;
getch();
}
//.......Coded by SAHIL SHAIKH
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class Student
{
public:
int id; // declaring members as public allowing us to modify them from outside the class
string name;
};
int main()
{
Student s1;
s1.id = 2; // modifying id and name from outside the class
s1.name = "Abhishek";
cout << s1.id << endl;
cout << s1.name << endl;
return 0;
}
//.......Coded by SAHIL SHAIKH
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP