[JNI] 开发基础(1) c语言基本类型

来源:互联网 发布:2017年淘宝云客服招聘 编辑:程序博客网 时间:2024/05/22 03:48

头文件:
头文件引入,这个相当于java导入引用文件包,在编写的时候手动导入,有一部分ide会提示需要什么h文件

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <Windows.h>

hello world

学习什么语言,习惯性的从hello world开始

void main(){    printf("hello world\n");    //这句是让窗体暂停,方便查看输出结果     system("pause");}

基本变量:
与java语言的基本变量基本类似,有6个关键字short、int、long、char、float、double 代表C 语言里的六种基本数据类型。详细情况就不多说,有java基础的很好理解。

**int %dshort %dlong %ldfloat %fdouble %lfchar %c%x 16进制%o 8进制%s 字符*/void main(){    int i = 10;    //输出int %d    printf("%d\n",i);    float f = 23.3;    //输出float %f    printf("%f\n",f);    char c = 'a';    //输出char %c    printf("%c\n",c);    //大小    printf("int?%d字节\n",sizeof(int));    printf("char?%d字节\n", sizeof(char));    printf("float?%d字节\n", sizeof(float));    //for循环    int n = 0;    for (; n < 10; n++){        printf("%d\n",n);    }     // 输出字符串     printf("输出字符串:%s\n", "this is str");    // 输出八进制     printf("输出八进制:%#o\n", 03);    // 输出十六进制    printf("输出十六进制:%#x\n", 0x23);    system("pause");}

在32 位的系统上

short 内存大小是2byteint 内存大小是4bytelong 内存大小是4bytefloat 内存大小是4bytedouble 内存大小是8bytechar 内存大小是1byte

通个sizeof(TYPE)可以得到对于TYPE的大小

了解完基本类型后,写一个倒计时实例:

void main(){    int time = 10;    printf("time:%#x\n",&time);    while (time > 0){        time--;        printf("%d\n",time);        //每隔1秒        Sleep(1000);    }    system("pause");}
0 0
原创粉丝点击