A Short Exercise

From WikiEducator
Jump to: navigation, search

Try to find the error or output:

 #include<string.h>
 main( )
 {
   char * MyName = “Kamal Kant Gupta”;
   int i = 0;
   while( I <= strlen(MyName) -1 )
   {
     cout<< *(MyName + i)<<”\n\t”;
   }
   getch( );
 }

Q : Observe the following two codes and then put your views about one of them which you feel is better implementation than the other. (Both the implementations solves a same problem). Give reasons

main( )
 {
char *book = “The Alchemist”; char *book = “The Alchemist”;
while( *book != ‘\0’)
{
cout<< *book ;
book++;
}
}
main( )
 {
char *book = “The Alchemist”;
int i = 0 ;
while( *(book+i) != ‘\0’)
{
cout<< *(book+i) ;
i++;
}
}

click the link below to post your comment , response , reflections to the above question

  http://wikieducator.org/Talk:A_Short_Exercise