전산 관련 시험/프로그래밍(C, JAVA, Python)46 [C] 프로그래밍 언어 (문자열의 비교와 Case문) #include int str_cmp(const char* s1, const char* s2, int c) { if (!c) return 0; while (--c && *s1 && *s1 == *s2) { printf("*"); s1++; s2++; } return *s1 - *s2;}int main() { int result = str_cmp("abcd", "abcD", 10); switch (result) { case 0: printf("equal"); break; default: printf("difference".. 2024. 10. 17. [C] 프로그래밍 언어 (ex. 23) Stack 이해 #include #define MAX_SIZE 5int stack[MAX_SIZE]; // 스택 배열int p = -1; // 스택 포인터int isEmpty() { if (p == -1) return 1; return 0;}int isFull() { if (p == MAX_SIZE - 1) return 1; return 0;}void push(int num) { if (isFull()) { printf("Full"); return; } stack[++p] = num;}int pop() { if (isEmpty()) { printf("Empty"); return -1; // -1을 반환하여 에러 처리 .. 2024. 10. 17. [C] 프로그래밍 언어 (ex. 19) int a[3][3] = { 10, 20, 30, 40, 50, 60, 70, 80, 90 }; int (*p)[3]; p = a; printf("%d", *(p[2] + 1) - *(p[0] + 3)); 코드 분석: int a[3][3] = { 10, 20, 30, 40, 50, 60, 70, 80, 90 }; int (*p)[3]; p = a; printf("%d", *(p[2] + 1) - *(p[0] + 3)); •**배열 a[3][3]**는 2차원 배열로 다음과 같은 값들을 가집니다: 10 20 30 40 50 60 70 80 90 •**포인터 p**는 3개의 정수로 이루어진 배열을 가리키는 포인터로 선언되었으며, 배열 a의 시작 주소를 가리키도록 설정됩니다. •printf의 식: •*(p[2].. 2024. 10. 16. [JAVA] 프로그래밍 언어 (ex. 28) class A { private int a; // 변수 a는 private으로 선언됨 public A(int a) { this.a = a; // this.a = a; (1번 빈칸) } public void display() { System.out.println("a=" + a); } } class B extends A { public B(int a) { super(a); // super(a); (2번 빈칸) super.display(); // 부모 클래스의 display() 호출 } } public class Eunwoo { public static void main(String[] args) { B b = new B(50); // B 클래스 객체 생성 } } 설명 1. 첫 번째 빈칸 (this.a = .. 2024. 10. 15. 이전 1 2 3 4 ··· 12 다음