本文介绍了如何在不使用sizeof运算符但使用按位运算符的情况下计算int的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 请不要使用指针算法或for循环 解决方案 解决方案 将unsigned int设置为1,使用左移运算符<< ,测试它是否为零。 gtoomey Please do not use pointer arithmetic or for loopsSolution 解决方案Set an unsigned int to 1, use the left shift operator << , test whether itszero.gtoomey#include <stdio.h>#define FAIRLY_LARGE 32767int main(void){char buf[FAIRLY_LARGE] = {0};puts("Please enter the size of an int, in bytes.");if(fgets(buf, FAIRLY_LARGE, stdin) != NULL){~fputs("The size of an int, in bytes, is ", stdout);puts(buf);}return 0;}Now here''s a little puzzle for you in return:RG8gWW91ciBPd24gSG9tZXdvcmshDQo=Enjoy! 这篇关于如何在不使用sizeof运算符但使用按位运算符的情况下计算int的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!