diff --git a/1.cpp b/1.cpp index 190c209..7d4ae8d 100644 --- a/1.cpp +++ b/1.cpp @@ -6,8 +6,11 @@ class container { int size; public: float* p; - container(int s) :size(s){} - const int& getsize() { return size;} + container(int s) :size(s) { + } + const int& getsize() { + return size; + } }; @@ -15,12 +18,12 @@ class vector :public container { int call_num; public: - explicit vector(int l) :len(l),size(1 * 100){ + explicit vector(int l) :len(l), container(1 * 100) { p = new float(); - } + }; int len; - int& getlen() const { - call_num ++; + int& getlen() { + call_num++; return len; } ~vector() = default; @@ -29,12 +32,14 @@ class vector :public container { int main() { container c1(100); - vector v1 = c1; - container& r1 = v1; + //vector v1 = c1; + //container& r1 = v1; container c2 = 100; - c2.getsize() = 20; + //c2.getsize() = 20; cout << c2.getsize(); - vector v2 = 100; - v2.getlen = 40; - cout << v2.getlen(); -} \ No newline at end of file + //vector v2 = 100; + //v2.getlen = 40; + //cout << v2.getlen(); +} + +//res : 100 \ No newline at end of file diff --git a/2.cpp b/2.cpp index 6a27746..432cb78 100644 --- a/2.cpp +++ b/2.cpp @@ -5,9 +5,9 @@ using namespace std; // count all the specific char in the whole array of strings int countAllSpecificChars(string sArr[], int arrLength, char specificChar) { - int count; - for (int i = 0; i <= arrLength; ++i) - for (int j = 0; j <= sArr[i].size(); ++j) + int count = 0; + for (int i = 0; i < arrLength; ++i) + for (int j = 0; j < sArr[i].size(); ++j) // if the jth char of the string is the specific char if (sArr[i][j] = specificChar) count++; diff --git a/4.cpp b/4.cpp index a9a32f2..3749d46 100644 --- a/4.cpp +++ b/4.cpp @@ -2,8 +2,10 @@ int main() { float arr[5] = { 12.5, 10.0, 13.5, 90.5, 0.5 }; - float *ptr1 = &arr[0]; - float *ptr2 = ptr1 + 3; + float* ptr1 = &arr[0]; + float* ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; -} \ No newline at end of file +} +//res: +//78.00000 \ No newline at end of file diff --git a/5.cpp b/5.cpp index e9a1737..2378e9c 100644 --- a/5.cpp +++ b/5.cpp @@ -1,10 +1,15 @@ -#include + +#include int main() { int arr[] = { 10, 20, 30, 40, 50, 60 }; - int *ptr1 = arr; - int *ptr2 = arr + 5; + int* ptr1 = arr; + int* ptr2 = arr + 5; printf("%d\n", (*ptr2 - *ptr1)); printf("%c", (char)(*ptr2 - *ptr1)); return 0; -} \ No newline at end of file +} + +// res: +//50 +//2 \ No newline at end of file diff --git a/6.cpp b/6.cpp index bb721c3..a959681 100644 --- a/6.cpp +++ b/6.cpp @@ -1,11 +1,12 @@ -#include +#include int main() { int a; - char *x; - x = (char *)&a; + char* x; + x = (char*)&a; a = 512; x[0] = 1; printf("%d\n", a); return 0; } +//res : 513 \ No newline at end of file diff --git a/7.cpp b/7.cpp index 7b065a0..e6df2d1 100644 --- a/7.cpp +++ b/7.cpp @@ -2,9 +2,10 @@ int main() { int arr[] = { 1, 2, 3, 4, 5 }; - int *p = arr; - ++*p; + int* p = arr; + ++* p; p += 2; printf("%d", *p); return 0; -} \ No newline at end of file +} +//res :3 \ No newline at end of file diff --git a/8.cpp b/8.cpp index 76b870c..c7890b7 100644 --- a/8.cpp +++ b/8.cpp @@ -1,13 +1,12 @@ -#include -const char * f(const char **p) { +#include +const char* f(const char** p) { auto q = (p + sizeof(char))[1]; return q; } int main() { - const char * str[] = { "Wish","You","Best",":D" }; + const char* str[] = { "Wish","You","Best",":D" }; printf("%c%c ", *f(str), *(f(str) + 1)); printf("%c%c%c%c\n", **str, *(*(str + 1) + 1), *((str + 2)[-1] + 1), **&*(&str[-1] + 1)); - - - } + +//re: Be WooW