๐ก
๋ฐ๋ฐฐ์จ 2.6~ ๋ณธ๋ฌธ
2.6 printf() ํจ์์ ๊ธฐ๋ณธ์ ์ธ ์ฌ์ฉ๋ฒ
printf()
#includ <stdio.h>
int main()
{
// print formatted
printf("\"THe truth is ... \ni am Ironman.\n\"");
// escape sequence
return 0;
}
\n ์ค๋ฐ๊ฟ
"" ๋ฌธ์์ด ์ถ๋ ฅ
""๋ฅผ ์ถ๋ ฅ ํ๊ณ ์ถ๋ค๋ฉด?
"\" ~~~~\""
#include <stdio.h>
int main()
{
int x, y, z;
x=1;
y=2;
z=x+y;
printf("The answer is %i.", z);
// printf("%i + %i = %i.", x, y,z);
return 0;
}
๋ณ์์ ์ ์ฉ๋ ๊ฐ์ ๋ํ๋ด๊ณ ์ถ์๋ %i(integer), %d ๋ ์ญ์ง์๋ฅผ ํํ
if)
printf("x + y =z");
๋ผ ํ๋ฉด
""๋ ๋ฌธ์์ด ๊ทธ๋๋ก ์ถ๋ ฅํ๊ธฐ ๋๋ฌธ์
x + y = z ๋ก ์ถ๋ ฅ๋จ
printf("\a"); ๊ฒฝ๊ณ ์
2.7 ์ฃผ์ ๋ค๋๋ฒ
/* */
๋ธ๋ก ์ฃผ์
๋ธ๋ก ์ฃผ์ ์์ ๋ธ๋ก ์ฃผ์X
//
2.9 ํจ์ ๋ง๋ค๊ธฐ
1.ํจ์๋ฅผ ํธ์ถํ๊ธฐ ์ ์ ํจ์ ์ ์ธ์ด ๋จผ์
#include <stdio.h>
void say_hello(void)
{
printf("Hello, Wolrd!\n");
return; // ์๋ต๊ฐ๋ฅ
}
int main()
{
say_hello();
say_hello();
say_hello();
say_hello();
say_hello();
return 0;
}
2.ํจ์ ์ ์ธ๊ณผ ์ ์๋ฅผ ๋ถ๋ฆฌ
#include <stdio.h>
void say_hello(void); // prototyping, function declaration
int main()
{
say_hello();
return 0;
}
void say_hello(void) // function definition
{
printf("Hello, Wolrd!\n");
return;
}
'๋ฐ๋ฐฐ์จ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐ๋ฐฐ์จ 4.5 ~ (0) | 2021.01.08 |
---|---|
๋ฐ๋ฐฐ์จ 4.1 ~ (1) | 2021.01.07 |
๋ฐ๋ฐฐ์จ 3.7 ~ (0) | 2021.01.07 |
๋ฐ๋ฐฐ์จ 3.1 ~ (4) | 2021.01.06 |
๋ฐ๋ฐฐ์จ 1.5~ (0) | 2021.01.06 |