来自计算机菜鸟的提问
c语言中void怎么用?求解求解。求师傅
void类型在c开发中常见的用法有2种:
(1)作为函数的返回值,如void add(int x,int y); 表示该函数吴返回类型,不需要返回值。
(2)使用void*指针来使用,比如作为函数的参数类型,如: int max(void* param); -->此时的void*表示可以使用任何类型的参数进行转换。如
int a = 10; //普通类型
max((int)&a);
-----------
typedef struct{int a;}str; //结构体
str S1 ;
S1.a = 2;
max((str)&S1);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void characterJudgment(const char ch)
{
if(isupper(ch)) puts("capital");
else if(islower(ch)) puts("small");
else if(isdigit(ch)) puts("number");
else puts("others");
return;
}
int main(int argc,char **argv)
{
char ch;
puts("请输入字符:");
scanf("%c",&ch);
characterJudgment(ch);
return 0;
}
/*供读者学习:
* (1)了解ASCII码中字符与数字关系
* (2)c语言中有头文件#include<ctype.h>,里面有关于字符的常见字符测试函数。
* /
void就是无返回值类型,很容易理解的