void strpat(char *str) //Here the string CBSE will be passed as pointer to string from main()
{ for(int i=0;str[i]>0;i++) //This will run till null or numeric value 0 means till end of string as passed value is a null terminated string
{ for(int j=0;j<=i;j++) //This will traverse the string based on value of i
{ cout<<str[j]; //This will print C, CB, CBS, CBSE based on value of i from 0 to end of string
} cout<<endl; //This will print a newline after each of loop of j
}
}
int main( )
{ char *t=”CBSE”; //Initialisation of a string as character pointing to its first ocation strpat(t); //character pointer is passed to function created above
return 0;
}
Notes
char *t=”CBSE”; //For this line warning or errors may come based on your compiler settings as string literal to char * conversion is not allowed in C++11 standard.