본문 바로가기

728x90
반응형

Programming/C++ 1

(9)
[C++] ShiftString #include using namespace std; char* ShiftLeftString( char* msg, int len ) { // 결과 문자열을 보관할 공간을 할당한다. char* copy_msg = new char[ len + 1 ]; // 원본 문자열의 첫번째 글자를 빼고 복사한다. for ( int i = 0; i < len - 1; ++i ) { copy_msg[i] = msg[ i + 1 ]; } // 원본 문자열의 첫번째 글자를 제일 뒤에 복사한다. copy_msg[ len - 1] = msg[ 0 ]; copy_msg[ len ] = NULL; return copy_msg; } int main () { char message[] = "BINGO JJANG!!!"; //cout
[C++] ReverseString Working #include using namespace std; char* revstr_dm(char* src, int len); int main__() { char orig[] = "ABCD"; cout
[C++] Chapter 11. Pointers and Dynamic Memory Management Pointer Array & Pointer Dynamic Memory Allocation Pointer Are designed to hold memory addresses as their vlaues a pointer contains the memory address Stack Memory vs Heap Memory Stack memory Compile time Assignment by Computer Heap Memory Runtime Assignment by Programmer Memory draw #include using namespace std; int main() { //Draw Memory contents //on the left hand side : address , in the middl..
[C++] Swap Function #include using namespace std; void swap_passByVal(int n1, int n2); void swap_passByRef(int& n1, int& n2); void swap_passByPtr(int* p1, int* p2); int main() { int num1 = 50, num2 = -60; cout
[C++] Chapater 7. Single-Dimensional Arrays and C-Strings Introducing Arrays a collection fo the same types of data int size = 4; double myList[size]; //Wrong const int size =4; double myList[size]; //Correct No Bound Checking C++ does not check array's boundary e.g., myList[-1] and myList[11] does not cause syntax errors dataType arrayName[arraySize]= {value0, value1, .... , valuek}; Wrong double myList[4]; myList={1.9, 2.9, 3.4, 3.5}; Implicit Size d..
[C++] Chapter 6. Functions funciton signature function overloading pass by value pass by reference pass by pointer function signature funciton name number of parameters type of parameters function overloading same name but not same number of parameters or type of parameters return type and pas-by-ref are not part of Function signature function Define a function function name number of parameters type of parameters Invoke ..
[C++] Chapter 2. Elementary Programming Reading Input from the keyboard use cin #include using namespace std; int main() { cout > Width; cout > Height; int area = Width * Height; cout
[C++] Chapter1. Introduction to Computers, Programs, and C++ Simple comsole output #include using namespace std; int main() { cout iostream : standard input output header file -> cout : is same printf of C cout and

728x90
반응형