·13 min read·Certification

[Information processing article writing] Utilization of programming language

C

variable declaration

  • Variable names cannot start with a number or consist of only numbers. No spaces allowed. Reservations are not possible.
  • ? else is a reserved word and cannot be used as a variable name. True is possible

string processing function

  • strcmp(s1, s2): A function that compares strings and returns 0 if they are equal, and a negative number if they are different.
  • strcat: Functions to concatenate two strings.

operation problem

#include <stdio.h>
int main(int argc, char *argv[]) {
int a=5, b=3, c=12;
int t1, t2, t3;
t1=a && b;
t2=a || b;
t3=!c;
printf("%d", t1+t2+t3);
return 0;
}
  • ? In C language, an integer is false if it is 0 and true if it is not 0.
  • Therefore, a, b, and c are all true.
  • Since t1 is all true, it has the value of 1, which is true.
  • Since all of t2 is true, at least one of them is true, so it has the value of 1, which is true.
  • t3 is false, the inverse of true, and has a value of 0.
#include <stdio.h>
struct st{
int a;
int c[10];
};
int main (int argc, char *argv[]) {
int i=0;
struct st ob1;
struct st ob2;
ob1.a=0;
ob2.a=0;
for(i=0; i<10; i++) {
ob1.c[i]=i;
ob2.c[i]=ob1.c[i]+i;
}
for(i=0; i<10; i=i+2) {
ob1.a=ob1.a+ob1.c[i];
ob2.a=ob2.a+ob2.c[i];
}
printf("%d", ob1.a ob2.a);
return 0;
}
  • ? Note that the second for statement increases by 2.
  • In the first for statement, ob1.c has a value of 0 to 9, and ob2.c has a value twice that of ob1.c.
  • In the second for statement, ob1.a = 2+4+6+8 = 20, ob1.b = 4+8+12+16 = 40, so the total sum is 60.
  • ❓ There is no separate addition sign at the end, so is it adding..?
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[] ) {
int arr[2][3]={1,2,3,4,5,6};
int (*p)[3]=NULL;
p=arr;
printf("%d, ", *(p[0]+1)+*(p[1]+2));
printf("%d", *(*(p+1)+0)+*(*(p+1)+1));
return 0;
}
// 8,9
  • 해설
  • The first arr declared contains 1, 2, and 3 in the first array, and the second is a secondary array with 4, 5, and 6.
  • Here, *p is a pointer to a random int array (3 spaces), and by matching with arr, it points to 1, 2, and 3 in order from the first index of arr.
  • Then, the expression *p[1] points to 4 as the first index because the 3 spaces are viewed as a group.
  • In the case of *p+1, it refers to the value following the first index of the internal array in the pointer.
  • printf("%d, ", *(p[0]+1)+*(p[1]+2)); Here, the *(p[0]+1) part refers to the address of 2 because there is no change in the pointer position and it is an internal movement.
  • Here, the *(p[1]+2) part points to 4, which has been moved down one level by changing the pointer position, and refers to the address of 6 by moving it 2 spaces internally.
  • That is, they add up to 8.
  • printf("%d", *(*(p+1)+0)+*(*(p+1)+1)) Same as above, the *(*(p+1)+0) part refers to the address of 4 since there is no internal movement after the pointer moves to level 1.
  • The *(*(p+1)+1)) part refers to the address of 5 because it is 1 internal movement after moving the pointer 1 step.
  • That is, they add up to 9.
  • #include <stdio.h>
    #include <stdlib.h>
    int main(int argc, char *argv[] ) {
    char str1[20]="KOREA";
    char str2[20]="LOVE";
    char* p1=NULL;
    char* p2=NULL;
    p1=str1;
    p2=str2;
    str1[1]=p2[2];
    str2[3]=p1[4];
    strcat(str1, str2);
    printf("%c", *(p1+2));
    return 0;
    }
    
    • strcat functions to concatenate two strings. It doesn't make much sense in the problem, but...
    • Note that the positions of *p1 and *p2 have not changed here.
    • If p1=str1, p1 points to the value of 'K', and if p2=str2, p2 points to 'L'.
    • If str1[1]=p2[2], the value of "O" in str1[1] is replaced with 'V', which is moved two spaces from p2.
    • If str2[3]=p1[4], the value of "E" in str2[3] is replaced with 'A', which is moved four places from p1.
    • As a result, printf("%c", *(p1+2)) outputs 'R', which is the value shifted two spaces from p2.
    // C언어에서 정수 변수 a, b에 각각 1, 2가 저장되어 있을 때 다음 식의 연산 결과로 옳은 것?
    a
    • a
    • a
    • As a result, both are true, so they have the value of 1.
    #include 
    #include 
    int main(void) {
    char str[50]="nation";
    char *p2="alter";
    strcat(str, p2);
    printf("%s", str);
    return 0;
    }
    // nationalter
    
    • strcat(str, p2); Outputs the two as a combined string.

    Python

    • A scripting language published by Guido van Rossum that is interpreter-based, object-oriented, easy to learn, and highly portable.

    data type

    Data types, strings and lists, tuples, dictionaries, and sets
    • 튜플 corresponds to the Sequence data type and can store various data types in a given order, but the stored contents cannot be changed.
    • If you want to change the content, you cannot change the content of that part like a list, so you have to change and save it separately.

    operation problem

    • if, elif, else
    a=["대", "한", "민 ", "국"]
    for i in a:
    print(i)
    
    • ? In Python, print() outputs results with a line break at the end.
    def cs(n);
    s=0
    for num in range(n+1);
    s+=num
    return s
    print(cs(11)) // 66
    
    • Note that it is up to 12, not 11.
    • Sum from 0 to 12

    JAVA

    Exception

    • Errors that occur during run time that may result in malfunctions or adverse effects on results.
    • Error that occurs when the array index exceeds its range
    • Error that occurs when trying to read a file that does not exist
    • ? Grammatical errors in programming languages ​​correspond to ‘errors’.

    operator

    • ? The operator with the lowest priority is the assignment operator (=).

    operation problem

     

    modularization

    • Software modules can be expressed as subroutines, functions, etc. in programming languages.
    • As the number of modules increases, the size of each module relatively decreases, and interaction between modules increases, causing an overload phenomenon.
    • ? Modularization allows systems to be managed intelligently and helps solve complexity problems.
    • Modularity facilitates maintenance and modification of the system.

    build tool

    • Ant, Maven, Gradle
    • ? Kerberos: A computer network authentication encryption protocol that operates based on “tickets.”

    OSI Layer 7

    Application > Representation > Session > Transport > Network > Data Link > Physical

    data link layer

    • Protocol: ? HDLC, PPP, LLC

    application layer

    • Protocol: HTTP

    network layer protocol

    IP protocol

    • ? Header Length indicates the header length of the IP protocol in 32-bit word units.
    • ? Packet Length indicates the length of the entire packet including the IP header, and the maximum size is 232-1 bit.
    • Time To Live specifies the time a sending host can survive on the network before transmitting a packet.
    • Version Number indicates the version number of the IP protocol.
    • ? It mainly functions to specify addresses and set routes.
    • ? Checksum function is provided and calculated with the checksum field set to '0'.
    • If you look at the header formats of IP, UDP, and TCP, there is space for checksum.
    • This part is used to check if data is altered or broken while the packet header is being transmitted.
    • Checksum: A method of protecting the integrity of transmitted data in the form of redundancy checking.
  • ? It also performs the function of splitting and merging packets.
  • ? Provides non-connected services.
  • ? Provides a transmission function based on the Best Effort principle.
  • IP 주소체계

    • IPv4 display method: 4-part decimal number of 8 bits each
    • IPv4 automatically sets the host address and supports unicast.
    • IPv4 has different network and host address lengths for each class.
  • IPv6 notation: 8-part hexadecimal number of 16 bits each
  • Unlike IPv4, IPv6 packet headers can be of arbitrary length (extended header).
  • IPv6 can easily connect a user's terminal to the network through the address auto configuration function.
  • 2128 addresses can be expressed.
  • Packets can be classified by class and service, making quality assurance easy.
  • Security functions are provided through extension functions.
  • Class A Class IP addresses range from 0.0.0.0 to 127.255.255.255
  • Class with the largest number of hosts that a network can have
  • The first is 0 and the rest is 0 or 1.
  • Class B IP ranges are 128.0.0.0 to 191.255.255.255, networks starting with 10
  • C class? IP range is 192.0.0.0 to 223.255.255.255
  • Network range starting with 110
  • ? Calculation problem 0/24 This part can have 8 digits, and since there are 4 subnets, it is 22, so 2 are used as network IDs.
  • Therefore, the fourth usable ID is 11000000 ~ 11111111, so it has a value of 192 ~ 255.
  • Here, since it is the 4th available IP, it becomes 192 (minus), 193, 194, 195, and 196.
  • 255 for broadcast IP
  • ICMP(Internet Control Message Protocol)

    • A protocol used to transmit error information in case a transmission error occurs during the IP operation process in the TCP/IP layer structure.

    TCP protocol

    TCP header

    • Sequence Number: A number is assigned to each byte being transmitted.
    • Acknowledgment Number: Defines the number of bytes to be received from the other host.
    • Checksum: Checks for errors in segments containing data.
    • ? The window size is the buffer size on the transmitting and receiving side, and the maximum size is 65,535 bytes.

    transport layer protocol

    TCP protocol, connection-oriented

    • Flow Control, Error Control, Congestion Control
    • Provides two-way connection service
    • Provides a service in the form of a virtual circuit connection

    UDP protocol, connectionless oriented

    • Simple header structure reduces overhead. Transmission speed is fast.
    • ? Sequential transmission of data is not guaranteed.
    • Unlike reliable TCP, it does not perform flow control, error control, or congestion control.
    • It is often used in services that are completed with a single packet transmission and reception.

    routing protocol

    RIP routing protocol

    • To manage routing information, a distance vector algorithm is used to dynamically determine the shortest path depending on the number of passing routers (Hop Count).
    • ? The path selection metric is Hop Count.
    • When routing protocols are classified into IGP and EGP, it corresponds to EGP. Protocol for establishing IGP internal routes
    • EGP Protocol for establishing a route that can be accessed from the outside to the inside
  • ? The Bellman-Ford algorithm is used to search for the shortest path.
  • ? Each router updates its routing table using information received from neighboring routers.
  • There are cases where the path is not optimal.
  • Only count up to 15
  • Hop Count

    • The part of the route located between the origin and destination
    • The hop itself can be thought of as a router.

    process

    • Classification of programs, processors, and processes
    • Dispatch: This refers to the process changing from the ready state to the running state when a processor is assigned.
    • Process Control Block (PCB): Consists of information such as process identifier and process status.
    • ? Context Switching: The process of storing the contents of the status register of a previous process and loading the register of another process.
    • ? A thread exists within a process.

    process scheduling

    preemptive scheduling

    Shortest Remaining Time (SRT), round-robin scheduling, multi-level queue, multi-level feedback queue scheduling

    non-preemptive scheduling

    First come first service (FCFS), Shortest job first (SJF), Priority, Highest response next (HRN)
    • A scheduling technique that prevents another process from forcibly taking over an already allocated CPU.
    • HRN Scheduling? A non-preemptive scheduling technique that complements the weaknesses of the least-job-first (SJF) technique.
    • Priority = (waiting time + service time) / service time
  • Among the SJF scheduling queue processes, the average waiting time is reduced by performing those with the shortest execution time first.
  • Priority scheduling is performed in order of priority, increasing response speed.
  • When assigning priority dynamically, implementation is complicated and there is a lot of overhead.
  • disk scheduling

    FCFS scheduling, SSTF scheduling, SCAN and LOCK scheduling, C-SCAN scheduling

    SSTF Scheduling

    • A technique that serves the request closest to the current head first

    File Descriptor

    • It is an abstract representation used in Unix OS to access files or other input/output resources, such as network sockets.
    • It contains the information the system needs for file management.
    • It is stored in auxiliary memory, and when the file is opened, it is moved to main memory.
    • ? It is an integer representing a file or socket allocated from the system.
    • Also called File Control Block.

    operating system

    UNIX

    • One or more tasks can be performed in the background.
    • ? Supports multiple users and multiple tasks.
    • ? It has a tree-structured file system.
    • It is highly portable and has high compatibility between devices.
    • Most of them are written in C language and are highly portable.

    configuration

    • Hardware > Kernel > Shell > Utilities > User
    • The main function of the shell is to interpret user commands and transmit them to the kernel.
    • Provides programming functions to create repetitive command programs.
    • Provides the ability to set the user environment using an initialization file.
  • The main function of the kernel is to manage processes and memory to execute shell programs.
  • cohesion and binding

    ? Design with high cohesion and low coupling.

    Cohesion

    Functional > Sequential > Communication > Procedural > Temporal (temporal) > Logical > Accidental
    • Cohesion is a concept that represents the independence of a module and the degree of connection between components within the module.

    Temporal cohesion

    • When components within a module execute different functions together at the same time

    Coupling

    Content > Common > External > Control > Stamp > Data (data)
    • Cohesion refers to the degree of connection with external modules rather than within the module or the degree of interdependence between modules.
    • Allowing modules to share variables or exchange control information increases the degree of coupling.

    Content Cohesion

    • When one module references the internal functions and materials of another module

    Automatic Repeat Request (ARQ)

    ? error control

    • Stop-and-wait ARQ: Wait until ACK is received one by one before transmitting
    • Go-back-N ARO: Send multiple items at once, receive one positive acknowledgment (ACK), and transmit subsequent data
    • Selective-Repeat ARQ: Retransmit only the error part
    • Adaptive ARQ: A method of increasing transmission efficiency by adaptively reducing the number of ARQs

    Mutual Exclusion Technique

    • A technique that allows only one process to use a shared resource at any time and prevents other processes from accessing the shared resource.
    • When multiple processes use a shared resource simultaneously, each process takes turns using the shared resource. How to maintain critical areas
    • Dekker algorithm ensures that there is no deadlock, guarantees mutual exclusion, and is resolved by software without separate commands.

    synchronization technique

    Semaphore

    • Prevents multiple processes or threads from accessing shared resource data or critical sections (i.e., there is more than one synchronization target)
    // ? 임계 구역의 접근을 제어하는 상호배제 기법
    P(S) : while S<=0 do skip;
    S :=S-1;
    V(S) : S :=S+1;
    

    Mutex

    • Prevents one process or thread from accessing shared resource data or critical sections (i.e., there is only one synchronization target)

    memory placement strategy

    first-fit first-fit

    • Technique for finding and allocating the first available space in main memory ### best-fit
    • Use the smallest possible space

    worst fit worst-fit

    • How to use the largest

    Terms related to

    • Internal fragmentation: Size of space remaining after division
    • External fragmentation: Space created by a size smaller than the program.
    빈 기억공간의 크기가 20KB, 16KB, 8KB, 40KB일 때 기억장치 배치 전략으로 “Best Fit"을 사용하여 17KB의 프로그램을 적재할 경우 내부단편화의 크기는 얼마인가?
    >> 17KB 프로그램이므로 가능한 공간 중 가장 작은 공간인 20KB를 선택하게 되고, 내부 단편화의 크기는 남는 공간이므로 3KB가 된다.
    

    page replacement algorithm

    FIFO page replacement algorithm

    Optional page replacement algorithm

    LRU page replacement algorithm

    You might also like…