很基础的一些问题,求解答

arllarll 2011-02-26 03:57:50
疑问:
1.我们调用函数时,不清楚函数是否已经声明怎么办?

不清楚的情况下最好显示声明下,添加.h文件或者extern声明。

2.
typedef struct
{
LONG lIndex;
SHORT sLevel[6];
CHAR cPos;
} REC;
REC stMax,*pMax;
CHAR str[] = “Hello”;
CHAR *pChar = str;
ULONG ulGrade = 10;
USHORT usClass = 10;
DOUBLE dWeight;
UCHAR* pCharArray[10][10];

3.怎么判断自己的系统是大头还是小头的?写一个函数


4.看看下面函数的执行结果。
char *p1 = "123";
char a[10] = {'0', '1','0', '1','0', '1','0', '1','0', '1'};
char *p2 = "456";
printf("%s", a);

5.字符串注意是双字节的还是单字节的。
unicode 0x00 0x35

strlen();
wstrlen();
...全文
191 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
s07ka 2011-02-27
  • 打赏
  • 举报
回复
10分
evencoming 2011-02-27
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i=0x1020304;
char *chptr=(char *)&i;
printf("%d ",(int)(*chptr++));
printf("%d ",(int)(*chptr++));
printf("%d ",(int)(*chptr++));
printf("%d ",(int)(*chptr++));
system("pause");
return 0;
}
看看数值。如果依此输出 1 2 3 4为大头头,4 3 2 1小头。
当然,可以任意改进。
pathuang68 2011-02-26
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 proghua 的回复:]

上面有个错误修正一下
C/C++ code
int i = 1;
if (*((char *)&i) == 1)
Little_Endian;
else
Big_Endian;
[/Quote]

proghua 2011-02-26
  • 打赏
  • 举报
回复
上面有个错误修正一下
int i = 1;
if (*((char *)&i) == 1)
Little_Endian;
else
Big_Endian;
proghua 2011-02-26
  • 打赏
  • 举报
回复
int i = 1;
if (*((char *)&i) = 1)
Little_Endian;
else
Big_Endian;
proghua 2011-02-26
  • 打赏
  • 举报
回复
请写一个C函数,若处理器是Big_endian的,则返回0;若是Little_endian的,则返回1
解答:
int checkCPU( )
{
union w
{
int a;
char b;
} c;
c.a = 1;
return(c.b ==1);
}
jixingzhong 2011-02-26
  • 打赏
  • 举报
回复
3.http://blog.csdn.net/jixingzhong/archive/2007/01/17/1486110.aspx

#include <cstdlib>
#include <iostream>

using namespace std;

union test
{
int i;
char c;
};

int main()
{
union test t;
t.i = 0x12345678;
if(t.c == 0x78)
cout<<"Little-endism"<<endl;
else
cout<<"Big-endism"<<endl;
system("pause");
return 0;
}
jixingzhong 2011-02-26
  • 打赏
  • 举报
回复
1.那就再声明一下
bdmh 2011-02-26
  • 打赏
  • 举报
回复
没有,你还调用什么,编译器也不让啊
大头小头,好像之前有人说过,用一个union体去判断,里面有两个字段,给其中一个字段赋值,然后判断另一个值
printf( "%s ", a); 这个a,你没有结束符,这样打印出来很可能乱套

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧