I had declared a static variable "id" which is incremented with static function but in the output it is displaying same value everytime. I have attached the output image .
`
class student
{
public:
string name;
static int id;
char sec;
student()
{
sec = 'A';
}
static int st_id()
{
id++;
return id;
}
void st_name()
{
cout << "Enter student name:";
cin >> name;
}
};
int student ::id = 0;
int main()
{
int num, i;
cout << "Enter the no. of students in class :";
cin >> num;
student *p = new student[num];
for (i = 0; i < num; i++)
{
p[i].st_name();
}
cout << endl
<< " NAME ID SEC" << endl;
for (i = 0; i < num; i++)
{
cout << i + 1 << ")"
<< " " << p[i].name << " " << p[i].st_id << " " << p[i].sec << endl;
}
}
`