Advertisement
35657

Untitled

Jan 13th, 2024 (edited)
1,324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.    
  7.     const int size = 4;
  8.    
  9.     char line[size] = { 'C', 'a', 't', '!' }; // символьный массив
  10.  
  11.     for (int i = 0; i < size; i++) {
  12.         cout << line[i];
  13.     }
  14.     cout << endl;
  15.  
  16.     const int size2 = 5;
  17.  
  18.     char line2[size2] = { 'C', 'a', 't', '!', '\0'}; // строка (символьный массив, который заканчивается терминальным нулем
  19.  
  20.     for (int i = 0; i < size2; i++) {
  21.         cout << line2[i];
  22.     }
  23.     cout << endl;
  24.  
  25.     int arr[5] = { 1,2,3,4,5 };
  26.     cout << arr << endl; // так нельзя
  27.     cout << line << endl; // так нельзя
  28.     cout << line2 << endl; // а так можно (так как это строка, она заканчивается терминальным нулем)
  29.  
  30.     char line3[40];
  31.  
  32.     cin >> line3;
  33.  
  34.     cout << line3 << endl;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement