Expand | Embed | Plain Text
- #include <iostream> #include <cstring> // for the strlen() function int main() {
- using namespace std; const int Size = 15; char name1[Size];
- // empty array
- char name2[Size] = Ã¢ï¿½ï¿½C++owboyÃ¢ï¿½ï¿½; // initialized array // NOTE: some implementations may require the static keyword // to initialize the array name2
- cout << Ã¢ï¿½ï¿½Howdy! IÃ¢ï¿½ï¿½m Ã¢ï¿½ï¿½ << name2; cout << Ã¢ï¿½ï¿½! WhatÃ¢ï¿½ï¿½s your name?\nÃ¢ï¿½ï¿½; cin >> name1;
- cout << Ã¢ï¿½ï¿½Well, Ã¢ï¿½ï¿½ << name1 << Ã¢ï¿½ï¿½, your name has Ã¢ï¿½ï¿½; cout << strlen(name1) << Ã¢ï¿½ï¿½ letters and is stored\nÃ¢ï¿½ï¿½; cout << Ã¢ï¿½ï¿½in an array of Ã¢ï¿½ï¿½ << sizeof(name1) << Ã¢ï¿½ï¿½ bytes.\nÃ¢ï¿½ï¿½; cout << Ã¢ï¿½ï¿½Your initial is Ã¢ï¿½ï¿½ << name1[0] << Ã¢ï¿½ï¿½.\nÃ¢ï¿½ï¿½; name2[3] = Ã¢ï¿½ï¿½\0Ã¢ï¿½ï¿½;
- // null character
- cout << Ã¢ï¿½ï¿½Here are the first 3 characters of my name: Ã¢ï¿½ï¿½; cout << name2 << endl; return 0;
- }
Report this snippet
Tweet