c语言变量示例,C语言变量示例程序

本篇文章帮大家学习c语言变量示例程序,包含了C语言变量示例程序使用方法、操作技巧、实例演示和注意事项,有一定的学习价值,大家可以用来参考。

一个变量是一个具有值的占位符。所有变量都有一些与它们相关联的类型,它们表示可以分配什么类型的值。C语言提供了一组丰富的变量 -

类型

格式字符串

说明

char

%c

字符类型变量(ASCII值)

int

%d

整数的大小

float

%f

单精度浮点值

double

%e

双精度浮点值

void

N/A

代表不存在类型

字符(char)变量

字符(char)变量包含一个字符。如下示例代码 -

#include

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

整数(int)变量

int变量保存单个字符的有符号整数值。如下示例代码 -

#include

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

浮点(float)变量

float变量保存单精度浮点值。如下示例代码 -

#include

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

双精度(double)浮点变量

double变量保存双精度浮点值。如下示例代码 -

#include

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

Void(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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值