0% found this document useful (0 votes)
9 views5 pages

C Array

The document explains how to use arrays within a class in C++, demonstrating the syntax for declaring an array as a private member. An example class 'stud' is provided, which includes member functions to get and display student data using arrays for names. The output of the example program shows the roll numbers and names of two students, illustrating the concept effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

C Array

The document explains how to use arrays within a class in C++, demonstrating the syntax for declaring an array as a private member. An example class 'stud' is provided, which includes member functions to get and display student data using arrays for names. The output of the example program shows the roll numbers and names of two students, illustrating the concept effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Using Arrays within a class

Arrays can be used within a class similar to that as used


in the main() function

The syntax and the declaration of Array inside the class


is given as follows:
Class class_name
{
private:
data_type array_name[size];
public:
Member functions;
};
 Let us consider an example to make clear of
the concept of using arrays inside the class

 Example
#include<iostream.h>
#include<conio.h>
class stud
{
private:
int r_no;
char name[25];
public:
void getdata(int r, char *sting)
{
r_no=r;
strcpy(name, string);
}
void putdata()
{
cout<<“ Roll no of the student is”;
cout<<r_no;
cout<<“\nThe name is”;
cout<<name;
Cout<<“\n”;
}
};
void main()
{
stud s1,s2;
s1.getdata(1,raja);
s2.getdata (2,rahul);
clrscr();
s1.putdata();
s2.putdata();
}

 The output of the above program is given as follows:

 Output:
Roll no of the student is 1
The Name is raja
Roll no of the student is 2
The Name is rahul

 Thus the above program gives a clear idea of the


concept of using arrays inside the class

 You can also try several other examples also

You might also like