如何在不使用sizeof运算符但使用按位运算符的情况下计算int的大小 [英] How to calculate size of an int without using the sizeof operator but using bitwise operator

查看:109
本文介绍了如何在不使用sizeof运算符但使用按位运算符的情况下计算int的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请不要使用指针算法或for循环

解决方案

解决方案

Manish_Ganvir写道:< br>

请不要使用指针算法或for循环
解决方案




将unsigned int设置为1,使用左移运算符<< ,测试它是否为
零。


gtoomey


是否有任何一线解决方案?<登记/>

Manish_Ganvir写道:
请不要使用指针运算或for循环



#include< stdio.h>


#define FAIRLY_LARGE 32767


int main(无效)

{

char buf [FAIRLY_LARGE] = {0};

puts("请输入int的大小,以字节为单位。);

if(fgets(buf,FAIRLY_LARGE,stdin)!= NULL)

{

~fputs( int的大小,以字节为单位,是,stdout);

puts(buf);

}

返回0 ;
}


现在here''sa小的难题:


RG8gWW91ciBPd24gSG9tZXdvcmshDQo =


享受!


Please do not use pointer arithmetic or for loops
Solution

解决方案

Manish_Ganvir wrote:

Please do not use pointer arithmetic or for loops
Solution



Set an unsigned int to 1, use the left shift operator << , test whether its
zero.

gtoomey


Is there any one line solution?


Manish_Ganvir wrote:


Please do not use pointer arithmetic or for loops
Solution



#include <stdio.h>

#define FAIRLY_LARGE 32767

int 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的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆