본문 바로가기

포인터8

[C++] C++ 11/14/17/... New Types (ENG) nullptr The old C style of NULL is a number. // Class.h float GetScore(const char* name); // meant to call this float GetScore(int id); // actual // Main.cpp #define NULL 0 Class* myClass = new Class("COMP3100"); // ... int score = myClass->GetScore(NULL); So in C++ 11, you can use nullptr as a pointer. typedef decltype(nullptr) nullptr_t; // null pointer constant int number = NULL; // OK int* p.. 2022. 1. 2.
[C++] Standard Template Library Container: Vector (ENG) STL Container vector, map, set, stack, queue, list, deque ... STL container is a standard interface for all template-based containers. It allows for automatic memory management. Creating Vectors Vector is a dynamic array that can hold any data type. All elements in a vector are located in contiguous memory. Memory is automatically managed as the number of elements increase. You can randomly acce.. 2022. 1. 2.
[C++] String (ENG) std::string Class A string is not an array, but a class in C++. A string using a std::string class can be increased in length. #include std::string name; std::cin >> name; also possible to assign and append. It is intuitive and secure. string firstName = "Pury"; string fullName = "Onion"; // assignment fullName = firstName; // appending fullName += "Bab"; concatenation: string firstName = "Pury".. 2021. 12. 5.
[C++] New Concepts (ENG) Bool Data if (IsHero() == false) { // ... } if (IsHero() == true) { // ... } Reference Alias. Can not be NULL. Must be initialized when declared. int number = 100; int& reference = number; Can not change what refer to. int number1 = 100; int number2 = 200; int& reference = number1; reference = number2; // number1 == 200, number2 == 200, reference == 200 Reference as a parameter: // pointer void .. 2021. 12. 5.
[C 프로그래밍 실습] Report 04 Program 1 다음 내용을 참고로 구조체 employee를 정의하고, 아래 출력 화면의 내용으로 직원 4명의 정보를 초기값으로 설정하여 출력하시오. 그리고 사번 또는 이름과 새로운 인센티브를 입력하여 변경된 연봉을 출력하도록 하는 프로그램을 작성하시오. (Lab 10 동일문제) 구조체 person 멤버의 구성 : 사번, 이름, 전화번호 구조체 employee : 멤버의 구성 : person, 월급, 인센티브 연봉은 구조체의 멤버가 아니며 계산하여 출력 연봉 = 월급 * (12 + 인센티브/100)로 계산 출력 화면 1) 문제 해결 방법에 대한 설명 _Person 구조체와 _Employee 구조체를 만들어 사용 Line 24에서 연봉 직접 계산하여 출력 사용자 정의 함수 : _Employee 구조체 배.. 2021. 1. 8.
[C 프로그래밍 실습] 함수와 포인터 활용 2 (Lab 11) Program 1 : 함수 포인터, void 함수 포인터 Program 2 : 가변인자 함수, 자료형 Program 3 : 가변인자 함수, 문자열 연결 Program 4 : 가변인자 함수, 자료형 Program 5 : 함수 포인터, 사칙연산, 0으로 나눌 때, 연산자 오류 Program 6 : void 포인터 배열 Program 1 다음 프로그램에서 문법오류 및 실행오류를 찾아 수정하시오. 아래 코드를 눈으로 분석해 보고, 어떤 부분에서 문제가 있는지 확인후, 코드를 IDE에 복사하여 잘못된 부분 수정하고 컴파일하고 실행해 본다. #include void myprint(int x); int main() { void (*p)(int); p = myprint(); p(2); (*p)(4); return 0;.. 2021. 1. 7.
[C 프로그래밍 실습] 함수와 포인터 활용 1 (Lab 10) Program 1 : 이차원 배열(행렬) 출력, 더하기, 빼기 함수 Program 2 : 이차원 배열 포인터, 함수 Program 3 : 일차원 배열 최댓값, 최솟값 찾는 함수 Program 4 : 오름차순 정렬 배열 병합 Program 5 : 가변인자 함수 Program 6 : 가변인자 함수 Program 1 두 이차원 배열의 출력, 더하기, 빼기를 수행하는 함수를 만들고, 실행 예를 참고하여 배열의 연산 결과를 출력하는 프로그램을 작성하시오. 아래 내용을 이용하여 함수를 정의 하고 실행 #define ROWS 2 #define COLS 3 typedef double matrixa[ROWS][COLS]; typedef double matrixb[ROWS][COLS]; typedef double resu.. 2021. 1. 6.
[C 프로그래밍 실습] 반복 / 포인터 기초 (Lab 03) Program 1 : while(1) 반복문, break Program 2 : for 반복문, continue, break Program 3 : while 반복문 Program 4 : while, for 반복문 / 비트 연산자 (>>) 사용하여 정수 32비트로 출력 Program 5 : 16진수 비트 연산 (&, |, ^) Program 6 : int형 포인터 Program 7 : char형 포인터, 포인터 이동 / 16진수 바이트 단위 출력 Program 8 : double형 포인터 Program 9 : 8바이트 double형 변수 4바이트 int형 포인터로 나눠 int형 변수 저장 Program 10 : 문자열 포인터 / 대문자, 소문자, 숫자, 특수문자 개수 구하기 Program 1 표준입력으로 받.. 2020. 10. 27.