首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

问个memcmp使用的有关问题

2012-04-28 
问个memcmp使用的问题#include iostream#include string.husing namespace stdint main(){int a1in

问个memcmp使用的问题
#include <iostream>
#include <string.h>

using namespace std;


int main()
{
  int a=1;
  int b=256;
  if(memcmp(&a,&b,sizeof(int))<0)
  cout<<"1<256"<<endl;
  else
  cout<<"1>256"<<endl;


  return 0;
}

为什么输出 1>256,好像只比较了一个字节。
一直没搞清楚。
求教一下上述memcmp使用有什么问题?
多谢~

[解决办法]
a=1;在内存是这样存储的:01 00 00 00;

b=256;是这样的:00 01 00 00;

以上四个字节存储,该函数是按字节比较的,第一个字节,大小就已经确定,就不会往后比较,所以是大于0

热点排行