Learn-c-by-examples-variables-in-c
提供:Dev Guides
Cの変数
- 変数*は、ある値のプレースホルダーです。 すべての変数にはいくつかのタイプが関連付けられており、割り当て可能な値の「タイプ」を表します。 Cは変数の豊富なセットを提供しています-
Type | Format String | Description |
---|---|---|
char | %c | Character type variables (ASCII values) |
int | %d | The most natural size of integer for the machine. |
float | %f | A single-precision floating point value. |
double | %e | A double-precision floating point value. |
void | − N/A − | Represents the absence of type. |
Cの文字( + char +
)変数
文字( + char +
)変数は単一の文字を保持します。
#include <stdio.h>
int main() {
char c; //char variable declaration
c = 'A'; //defining a char variable
printf("value of c is %c", c);
return 0;
}
プログラムの出力は次のようになります-
value of c is A
Cの整数( + int +
)変数
`+ int +`変数は、単一文字の整数値を保持します。
#include <stdio.h>
int main() {
int i; //integer variable declaration
i = 123; //defining integer variable
printf("value of i is %d", i);
return 0;
}
プログラムの出力は次のようになります-
value of i is 123
Cの浮動小数点( + float +
)変数
`+ float +`変数は単精度浮動小数点値を保持します。
#include <stdio.h>
int main() {
float f; //floating point variable declaration
f = 12.001234; //defining float variable
printf("value of f is %f", f);
return 0;
}
プログラムの出力は次のようになります-
value of f is 12.001234
Cの倍精度( + double +
)浮動小数点変数
`+ double +`変数は、倍精度の浮動小数点値を保持します。
#include <stdio.h>
int main() {
double d; //double precision variable declaration
d = 12.001234; //defining double precision variable
printf("value of d is %e", d);
return 0;
}
プログラムの出力は次のようになります-
value of d is 1.200123e+01
Cのボイド( + void +
)データ型
Cの `+ void +`は、「なし」または「値なし」を意味します。 これは、ポインター宣言または関数宣言で使用されます。
//declares function which takes no arguments but returns an integer value
int status(void)
//declares function which takes an integer value but returns nothing
void status(int)
//declares a pointer p which points to some unknown type
void * p