Skip to content

Instantly share code, notes, and snippets.

@not7cd
Created November 1, 2017 22:11
Show Gist options
  • Save not7cd/3e85012c45d1ae21ad947dc33f504390 to your computer and use it in GitHub Desktop.
Save not7cd/3e85012c45d1ae21ad947dc33f504390 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
char str1[] = "All work and no play makes Jack a dull boy";
char str2[] = "All work and no play\0 makes Jack a dull boy";
char str3[] = "All work";
str3[8] = 'z';
char str4[] = {'n','o',' ','p','l','a','y','\0'};
str4[7] = ' ';
cout << str1 << endl << str2 << endl;
cout << str3 << endl << str4 << endl;
return 0;
}
/*
All work and no play makes Jack a dull boy
All work and no play
All workz=b�
no play �r�@&
*/
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
for (int i = 0; i < argc; ++i)
{
cout << argv[i] << endl;
cout << *argv[i] << endl;
cout << &argv[i] << endl;
}
return 0;
}
/*
~/.../cpp/tablice  ./t0 aaaa bbb cc d
./t0
.
0x7ffeec36f768
aaaa
a
0x7ffeec36f770
bbb
b
0x7ffeec36f778
cc
c
0x7ffeec36f780
d
d
0x7ffeec36f788
*/
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
char str1[] = "No play";
char *str2 = str1;
cout << str1 << endl << str2 << endl;
str2[2] = '-';
cout << str1 << endl << str2 << endl;
return 0;
}
/*
No play
No play
No-play
No-play
*/
#include <iostream>
using namespace std;
void fun_1(int *arr) {
arr[0] += 1;
cout << &arr << endl;
return;
}
void fun_2(int arr[]) {
arr[2] -= 1;
cout << &arr << endl;
return;
}
int main(int argc, char const *argv[])
{
int arr[] = {1, 2, 3};
for (int i = 0; i < 3; ++i)
{
cout << arr[i];
}
cout << endl;
fun_1(arr);
fun_2(arr);
for (int i = 0; i < 3; ++i)
{
cout << arr[i];
}
cout << endl;
return 0;
}
/*
123
0x7fffd8ed8a88
0x7fffd8ed8a88
222
*/
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
char str1[] = "No play";
cout << str1 << endl << &*str1 << endl;
cout << *str1 << endl << &str1 << endl;
char *str2 = str1;
cout << str2 << endl << &*str2 << endl;
cout << *str2 << endl << &str2 << endl;
return 0;
}
/*
No play
No play
N
0x7fff6b12b4d0
No play
No play
N
0x7fff6b12b4c8
*/
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
char str1[] = "No play";
cout << str1 << endl << &*str1 << endl;
cout << *str1 << endl << &str1 << endl;
for (int i = 0; i < 7; ++i) cout << str1[i];
cout << endl;
for (int i = 0; i < 10; ++i) cout << str1[i];
cout << endl;
int arr1[] = {1, 2, 3, 4, 5, 6 ,7};
cout << arr1 << endl << &*arr1 << endl;
cout << *arr1 << endl << &arr1 << endl;
for (int i = 0; i < 7; ++i) cout << arr1[i];
cout << endl;
for (int i = 0; i < 10; ++i) cout << arr1[i];
cout << endl;
return 0;
}
/*
No play
No play
N
0x7ffdd6f5bdf0
No play
No play�
0x7ffdd6f5bdd0
0x7ffdd6f5bdd0
1
0x7ffdd6f5bdd0
1234567
1234567018811738387954796
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment