C语言之1ULL/1UL/1L区别(五十五)
C语言 区别
2023-09-14 09:09:58 时间
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <iostream>
using namespace std;
#define I_MAX (1<<31) -1
#define I_MIN -(1<<31)
#define L_MAX (1ULL<<63) -1
#define L_MIN -(1ULL<<63)
//1ULL、1UL、1L:如果不指定的话就是默认的int类型,所以int类型的范围(1<<31 -1)较小
#define TEST_L_MAX (1<<63) -1
#define TEST_L_MIN -(1<<63)
int main(){
char *str = "23344232432342";
long long ret = 0;
printf("I_MAX = %d\n",I_MAX);
printf("I_MIN = %d\n",I_MIN);
//ok
printf("L_MAX = %lld\n",L_MAX);
printf("L_MIN = %lld\n",L_MIN);
//error
printf("TEST_L_MAX = %lld\n",TEST_L_MAX);
printf("TEST_L_MIN = %lld\n",TEST_L_MIN);
printf("sizeof(unsigned long long) = %d\n",sizeof(unsigned long long));
printf("sizeof(unsigned long) = %d\n",sizeof(unsigned long));
printf("sizeof(long) = %d\n",sizeof(long));
cout << endl;
printf("INT_MAX = %d\n",INT_MAX);
printf("INT_MIN = %d\n",INT_MIN);
printf("LONG_MAX = %ld\n",LONG_MAX);
printf("LONG_MIN = %ld\n",LONG_MIN);
printf("LLONG_MAX = %ld\n",LLONG_MAX);
printf("LLONG_MIN = %ld\n",LLONG_MIN);
while(*str >= '0' && *str <= '9'){
ret = ret*10 + (*str - '0');
str++;
}
printf("ret = %ld\n",ret);
}
打印:
I_MAX = 2147483647
I_MIN = -2147483648
L_MAX = 9223372036854775807
L_MIN = -9223372036854775808
TEST_L_MAX = 4294967295
TEST_L_MIN = 0
sizeof(unsigned long long) = 8
sizeof(unsigned long) = 8
sizeof(long) = 8
INT_MAX = 2147483647
INT_MIN = -2147483648
LONG_MAX = 9223372036854775807
LONG_MIN = -9223372036854775808
LLONG_MAX = 9223372036854775807
LLONG_MIN = -9223372036854775808
ret = 23344232432342
注意:如果没有ULL/UL/L后缀,则系统默认为 int类型.
1ULL:表示1是unsigned long long 类型(64位系统占8byte,64位)
1UL:表示1是unsigned long 类型(64位系统占8byte,64位)
1L:表示1是long 类型(64位系统占8byte,64位)
相关文章
- C语言 strstr函数的用法及模拟实现strstr函数「建议收藏」
- c程序设计,贪吃蛇程序是什么_C语言编写贪吃蛇
- C语言 01
- C语言之循环结构 for(一)详解编程语言
- 宏和函数的区别,C语言宏和函数区别详解
- typedef和define区别,C语言typedef和define的区别详解
- 数组指针和指针数组的区别,C语言数组指针和指针数组区别详解
- 字符数组和字符串的区别,C语言字符数组和字符串区别详解
- puts和fputs函数及其区别,C语言puts和fputs函数详解
- Linux下C语言求和的实现方法(linux的求和c语言)
- 语言在Linux下学习C语言(linux中c)
- C语言与MySQL结合开发测试程序(c 与mysql测试程序)
- 称MySQL连接示例用C语言轻松实现(c mysql连接实例名)
- C语言MySQL库数据库应用的强大工具(c mysql类库)
- C语言MySQL中用于生成随机数的方法(c mysql生成随机数)
- C语言MySQL驱动的注册登录应用实现(c mysql注册登录)
- MySQL数据库中C语言实现的主键机制(c mysql数据库主键)
- C语言实现与Oracle数据库连接的研究(c 连接oracle源码)
- 使用C语言递归与非递归实现字符串反转函数char*reverse(char*str)的方法
- 浅析C语言中printf(),sprintf(),scanf(),sscanf()的用法和区别
- C语言实现的bitmap位图代码分享