본문 바로가기
📍Certificate/Engineer Information Processing

[정보처리기사] 실기 프로그래밍언어 3문제 (29)

by Sun A 2024. 10. 12.

1️⃣ [JAVA]

2022.1회

다음 Java 코드의 출력 결과를 작성하시오.

class A {
  int a;
  int b;
}
  
public class Main {
  
  static void func1(A m) {
    m.a *= 10;
  }
  
  static void func2(A m) {
    m.a += m.b;
  }
  
  public static void main(String args[]){
  
  A m = new A();
  
  m.a = 100;
  func1(m);
  m.b = m.a;
  func2(m);
  
  System.out.printf("%d", m.a);
  }
}
2000

m 을 A 클래스로 새로 저장한다.

m.a = 100으로 선언했기에 func1(m) = 1000

m.a 값이 1000으로 으로 바뀌었기 때문에 m.b도 1000으로 계산

선언되고 func2(m)  => m.a = m.a + m.b = 1000 + 1000 = 2000

 

2️⃣ [C언어]

2021.3회

다음 C언어 코드에 대한 알맞는 출력값을 쓰시오.

#include 
 
struct jsu {
  char nae[12];
  int os, db, hab, hhab;
};
 
int main(){
  struct jsu st[3] = {{"데이터1", 95, 88}, 
                    {"데이터2", 84, 91}, 
                    {"데이터3", 86, 75}};
  struct jsu* p;
 
  p = &st[0];
 
  (p + 1)->hab = (p + 1)->os + (p + 2)->db;
  (p + 1)->hhab = (p+1)->hab + p->os + p->db;
 
  printf("%d\n", (p+1)->hab + (p+1)->hhab);
}
501

p+1은 st[1]의 주소를 가리킨다.

(p+1)의 os 값과 (p+2)의 db 값을 합쳐서 st[1]의 hab 값에 넣는 게 첫 번째 식이다. ((p+1) -> hab))

84 + 75 = 159

(p+1)의 hab 값과 p의 os, p의 db 값을 더한 게 st[1]의 hhab에 넣는 게 두 번째 식이다. ((p+1) -> hhab)

159 + 95 + 88 = 342

  nae os db hab hhab
st[0] "데이터1" 95 88    
st[1] "데이터2" 84 91 159 342
st[2] "데이터3" 86 75    

최종 값 : 159 + 342 = 501

 

3️⃣ [C언어]

2020.1회

다음은 C언어로 작성된 코드이다. 코드의 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include 
main( ) {
   int c = 1;
   switch (3) {
      case 1: c += 3;
      case 2: c++;
      case 3: c = 0;
      case 4: c += 3;
      case 5: c -= 10;
      default: c--;
   }
   printf("%d", c);
}
-8

0 + 3 - 10 - 1 = -8