Skip to content

Instantly share code, notes, and snippets.

@Zulqurnain
Created November 2, 2013 12:34
Show Gist options
  • Save Zulqurnain/5d4f5c67cf2ee43f815d to your computer and use it in GitHub Desktop.
Save Zulqurnain/5d4f5c67cf2ee43f815d to your computer and use it in GitHub Desktop.
Private array of pointers set in main !
#include <iostream.h>
#include <string.h>
class student
{
char *arr[5];
public:
void setarr()
{
char ar[100];
for(int i=0;i<5;i++){
cout<<"Enter Name :=:"; cin>>ar;
arr[i]=new char [strlen(ar)+1];
strcpy(arr[i],ar);
}
}
char getarr(int i,int j)
{
return arr[i][j];
}
~student(void){
for(int k=0;k<5;k++){
delete arr[k];
}
}
};
int main(){ // by Zulqurnain jutt
student s1;
s1.setarr();
for(int i=0;i<5;i++){
for(int j=0;s1.getarr(i,j)!='\0';j++)
cout<<s1.getarr(i,j);
cout<<"\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment