C/C++: Comment faire la différence entre un tableau et un pointeur

Author:

 pointeur
Download

#include 
using namespace std;

int main()
   {
   char str1[] = "String définit comme tableau";
   char* str2 = "String définit comme pointeur";

   /* Affichage des deux chaînes*/
   cout << str1 << endl;
   cout << str2 << endl;

// str1++;                  // Incorrect, car str1 est un constant
   str2++;                  // Correct, car str2 est un pointeur

   cout << str2 << endl;    // str2 pointe maintenant sur le deuxième élément de la chaîne
   return 0;
   }

Leave a Reply

Your email address will not be published. Required fields are marked *