본문 바로가기

Study Meeting/빡공단 30기

[Day 5] Standard input/output functions: scanf() and printf()

In this class, I learned about standard input and output functions including scanf() and printf() in C language.
"scanf()" function is basic input function that can receive users' input and "printf()" function is basic output function.

These input/output funtions can be used by declaring a header file <stdio.h>.
And we can declare this header file by adding the sentence #include <stdio.h> at the beginning of the code.

1. Input function: scanf("Input Type", Input variable)

#include <stdio.h>

/* Integer */
int Num1;
scanf("%d", &Num1);

/* Double */
doubel Num2;
scanf("%1f", &Num2);

/* Input one letter */
char Text1 = 'B';
scanf("Text1: %c", Text1);

/* Input one charater */
char Text2[10];
scanf("%s", Text2);


2. Output funtion: printf("Output Type or Contents", Output variable)

#include <stdio.h>

/* Integer */
int Num1 = 65536;
printf("%d", &Num1);

/* Double */
doube Num2 = 123.123;
printf("%1f", &Num2);

/* Input one letter */
char Text1 = 'B';
printf("Text1: %c", Text1);

/* Input one charater */
char Text2[10] = 'Hello';
printf("%s", Text2);