1.简述sizeof和strlen的区别 最常考察的题目之一。主要区别如下: 1)sizeof是一个操作符,strlen是库函数。 2)sizeof的参数可以是数据的类型,也可以是变量,而strlen只能以结尾为‘\0‘的字符串作参数。 3)编译器在编译时就计算出了...
分类:
编程语言 时间:
2015-04-10 14:58:32
阅读次数:
115
不使用sizeof,求某机器平台的int型整数位数(16,32,64)
思路,将整数变成字符串处理,并且在内存的末尾填零,即字符串结束符。
如 0x0012,0x00123456,0x00123456789ABCDE分别对应16,32,64位数; 小端机
代码
#include
#include
int main(int argc , char *argv[])
{
...
分类:
其他好文 时间:
2015-04-10 11:34:20
阅读次数:
191
#includeusing namespace std;int main(){ char s1[100],s2[100]; int res[100]; while(cin>>s1>>s2){ memset(res,0,sizeof(res)); int ...
分类:
其他好文 时间:
2015-04-09 21:47:05
阅读次数:
133
1)宏定义实现:
#define MySizeof(Value) (char*)(&Value + 1) - (char*)&Value
(char*)&Value返回Value的地址的第一个字节, (char*)(&Value + 1)返回的是Value的地址的下一个地址的第一个字节
#include
using namespace std;
#define my_sizeo...
分类:
其他好文 时间:
2015-04-09 19:49:02
阅读次数:
104
fd_set的实现详细原理
define FD_SETSIZE 1024
typedef unsigned long fd_mask;
#define NBBY 8 /* number of bits in a byte */
#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mas...
分类:
其他好文 时间:
2015-04-09 17:29:53
阅读次数:
149
关键字sizeof的作用是返回对象或类型占用的内存字节数,返回值是size_t。基本数据类型占用的字节数:(32位系统)char 1字节bool 1字节short 2字节int 4字节long 4字节float 4字节double 8字节 对sizeof结果的一个重要影响因素是字节对齐。首先看一个....
分类:
编程语言 时间:
2015-04-09 17:17:34
阅读次数:
166
struct Node{ int from,to,next;}edge[MAXM];int tol;int head[MAXN];void init(){ tol=0; memset(head,-1,sizeof(head));}void addedge(int u,int v){...
分类:
其他好文 时间:
2015-04-09 15:22:42
阅读次数:
120
首先,sizeof是一个操作符,不是一个函数,但是当操作数为类型名称时需要用小括号将类型名称包围起来(操作数为变量时不需要),这一规则使得sizeof看起来想一个函数一样。其次如果sizeof的操作数为静态数组名时,得到的结果是整个数组所占的空间大小(以byte为单位),但是如果操作数动态数组时,得到只是一个指针变量所占的用的大小(我的机器上是4byte)。这是因为数组和指针实际上是两个不同的对象(...
分类:
其他好文 时间:
2015-04-09 10:35:27
阅读次数:
292
(1)获取当前可执行文件路径:
#include
#pragma comment(lib, "shlwapi.lib")
wchar_t szExePath[MAX_PATH] = {0};
GetModuleFileNameW(NULL, szExePath, sizeof(szExePath));
PathRemoveFileSpecW(szExePath);...
#include
#include
#include
#include
#include
using namespace std;
#define mem(A) memset(A,0,sizeof(A))
#define N 10000010
int arr[10010];
int main()
{
int...
分类:
其他好文 时间:
2015-04-08 23:28:48
阅读次数:
482