Advertisement
Guest User

basic char array stuff

a guest
Sep 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6.     // char array[] = {'j','o', 'w', 'i','e'};
  7.     char array[] = "jowie";
  8.  
  9.     cout << array << endl; // will print the full array
  10.  
  11.  
  12.     for (size_t i = 0; i < sizeof(array); i++) {
  13.         cout << array[i] << endl; // So will this
  14.     }
  15.     cout << endl << endl;
  16.     for (size_t i = 0; i < sizeof(array); i++) {
  17.         cout << "Entry " << i << " contains: " << (int)array[i] << endl; // you are only able to make the extra entry visible if u cast it.
  18.         /*
  19.         you'll see that there is one entry added. This one is invisible, its called the NULL operator.
  20.         this way the C++ can know where your array actually stops.
  21.         */
  22.     }
  23.  
  24.     cout << endl << endl;
  25.  
  26.     char array_2[] = "florian";
  27.     int k = 0;
  28.     while (true) {
  29.  
  30.         /*if (array_2[k] == 0) {
  31.             break;
  32.         }*/
  33.         if (array_2[k] == NULL) { // NULL is in fact 0, hence why this works too. (The extra character is infact NULL(0)
  34.             break;
  35.         }
  36.  
  37.         cout << array_2[k] << flush;
  38.         k++;
  39.     }
  40.  
  41.     cin.get();
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement