-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathCPP026_String_Char_Pointers.cpp
67 lines (45 loc) · 1.23 KB
/
CPP026_String_Char_Pointers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Author: Tridib Samanta
* Created: 17.01.2020
**/
#include<iostream>
using namespace std;
int main() {
string text = "Hello"; // H e l l o \0
char ch = text[0];
char characters[]="Hello World";
cout<<characters<<endl;
cout<<characters[0]<<endl;
cout<<*(characters)<<endl;
cout<<characters[1]<<endl;
cout<<*(characters+1)<<endl;
cout<<endl<<endl;
char *p = characters;
cout<<p[0]<<endl;
cout<<*p<<endl;
cout<<p[1]<<endl;
cout<<*(p+1)<<endl;
cout<<endl<<endl;
string text1="Hey";
const char * text2 = text1.c_str();
cout<<text2<<endl;
char array[]="Sample Text";
string test = array;
cout<<test<<endl;
const char * a = "Test";
cout<<a<<endl;
char * const dynamic_array = new char[50];
dynamic_array[0]='k';
dynamic_array[1]='\0';
cout<<dynamic_array<<endl;
delete [] dynamic_array;
cout<<endl<<endl;
string array_of_strings[5]="qwerty";
array_of_strings[0]="abc";
array_of_strings[1]="def";
cout<<array_of_strings[0]<<endl;
cout<<array_of_strings[1]<<endl;
cout<<array_of_strings[2]<<endl;
//...
return 0;
}