본문 바로가기

프로그래밍

(5)
Reference(참조) vs. Pointer(포인터) in C++ C++로 dp관련 알고리즘 문제를 풀 때, 아래와 같이 참조(reference)를 종종 이용하곤 했다. void sol(int i,int j){ int& ref=s[i][j]; ... } 포인터와 유사한 듯한 이 참조는 포인터와 비교하여 어떤 차이가 있는지 궁금하여 알아보았다. Pointer 우선, 포인터는 다른 변수의 메모리 주소를 가지고 있는 변수로, 아래와 같이 사용한다. int a = 10; int *p = &a; 포인터가 가리키는 메모리 위치에 접근하기 위해서는 * 연산자(operator)를 사용하여 디레퍼런스(dereference)하는 과정이 필요하다. Reference 반면에, 참조 변수는 이미 존재하는 변수의 별칭(alias)이다. 내부적으로는 포인터와 같이 객체의 주소를 저장하도록 구현되..
[프로그래밍/C#] Event와 EventHandler 사용법 예제 클래스 내부 로직에서 발생하는 이벤트를 다른 클래스에 전달해야 하는 경우가 있다. Car 클래스에 현재 위치를 나타내는 _position, 목적지 위치를 나타내는 _destination 변수가 있고, 1초에 1씩 현재 위치를 증가시켜 목적지까지 도달하게 하는 Drive 메소드가 정의되어 있다. main 메소드에서는 Car 객체를 car라는 이름으로 목적지 위치를 3으로 주어 생성하고 car 객체의 Drive 메소드를 호출한다.12345678910111213141516171819202122232425262728class Program{ static void Main(string[] args) { Car car = new Car(3); car.Drive(); }} class Car{ private int _..
[프로그래밍/Python] 아두이노 HC-06 와 라즈베리파이 블루투스 RFCOMM 통신 참고 https://webnautes.tistory.com/979 bluetooth.ino 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include SoftwareSerial BTSerial(2, 3); //bluetooth module Tx:Digital 2 Rx:Digital 3 void setup() { pinMode(8, OUTPUT); //HC-05 digitalWrite(8,HIGH); Serial.begin(9600); BTSerial.begin(9600); Serial.println("ATcommand"); //ATcommand Start } void loop() { if (BTSerial.available()) Serial.write(BTSer..
[프로그래밍/Qt] Calculator 계산기 기능 구현 예제 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 12..
[프로그래밍/Qt] notepad 메모장 기능 구현 예제 mainwindow.h 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 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include #include #include #include #include #include #include #include #include #include class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); bool te..