include stdio h int main printfsize of char

  • Slides: 39
Download presentation

型の大きさを出力する #include <stdio. h> int main() { printf("size of char: t%d bytesn", sizeof(char)); printf("size

型の大きさを出力する #include <stdio. h> int main() { printf("size of char: t%d bytesn", sizeof(char)); printf("size of short: t%d bytesn", sizeof(short)); printf("size of int: t%d bytesn", sizeof(int)); printf("size of long: t%d bytesn", sizeof(long)); printf("size of float: t%d bytesn", sizeof(float)); printf("size of double: t%d bytesn", sizeof(double)); }

型の大きさ size size of of of char: 1 bytes s -128~+127 0 76 short:

型の大きさ size size of of of char: 1 bytes s -128~+127 0 76 short: 2 bytes s -32768~+32767 15 14 0 int: 4 bytes long: 4 bytes s 0 31 30 float: 4 bytes -2147483648~+2147483647 double: 8 bytes s 63 62 -1. 7 E-308 ~ 1. 7 E+308 0

switch文 switch(式){ case 定数: 処理;…; break; … default: 処理;…; break; } int monthday( int

switch文 switch(式){ case 定数: 処理;…; break; … default: 処理;…; break; } int monthday( int month ){ switch(month){ case 1: return 31; case 2: return 28; … case 12: return 31; } } 複雑な if 文を簡素化する際に使用

入出力関数: ライブラリと システムコール All I/O calls ultimately go to the kernel I/O library helps

入出力関数: ライブラリと システムコール All I/O calls ultimately go to the kernel I/O library helps with buffering, formatting, interpreting (esp. text strings & conversions) App #1 App #2 std. I/O Library Kernel

コンパイルのおさらい 単一ファイルの場合 %gcc -o program source 1. c 複数ファイルの場合 %gcc -o program source 1.

コンパイルのおさらい 単一ファイルの場合 %gcc -o program source 1. c 複数ファイルの場合 %gcc -o program source 1. c source 2. c もしくは %gcc -c source 1. c %gcc -c source 2. c %gcc -o program source 1. o source 2. o

Makefileの例 main : source 1. o source 2. o gcc -o program source 1.

Makefileの例 main : source 1. o source 2. o gcc -o program source 1. o source 2. o source 1. o : source 1. c gcc -c source 1. c source 2. o : source 2. c gcc -c source 2. c

Makefileの簡素化. cから. oファイルの生成ルール all : source 1. o source 2. o gcc -o program

Makefileの簡素化. cから. oファイルの生成ルール all : source 1. o source 2. o gcc -o program source 1. o source 2. o コンパイルオプションの変数化 <command> %gcc -Wall -g -c source 1. c <Makefile> CFLAGS = -Wall gcc ${CFLAGS} -c source 1. c

hello. cへの適用例 all: hello. o gcc -o hello. o: hello. c gcc -c hello.

hello. cへの適用例 all: hello. o gcc -o hello. o: hello. c gcc -c hello. c

課題1(cline. c) argc, argvを用いて引数を全て出力する。 実行例/出力例 %. /a. out 123 456 789 arg[0]: . /a.

課題1(cline. c) argc, argvを用いて引数を全て出力する。 実行例/出力例 %. /a. out 123 456 789 arg[0]: . /a. out arg[1]: 123 arg[2]: 456 arg[3]: 789

課題3 Makefileを作ってください 一行目は: all: hello size fortest cline numbers

課題3 Makefileを作ってください 一行目は: all: hello size fortest cline numbers