{
return NULL; }
return ptr; }
int main(int argc, char* argv[]) {
int msg_len ; char *pMsg;
if(TRUE == MaxMsgFlag) {
msg_len = MAX_MSG_LEN; }
pMsg = getBuffer(msg_len); if(NULL != pMsg ) {
strcpy(pMsg,\ printf(\ free(pMsg); }
return 0; }
上面的程序存在问题,下面描述正确的是( ) A、函数getBuffer应该判断入参msg_len是否大于0。 B、按照编程规范,函数main中pMsg应该赋初值 C、函数main中msg_len没有赋初值
三:填空题
1.
char *pcColor = \char acColor[] = \strlen(pcColor) = _____ strlen(acColor) = _____ sizeof(pcColor) = _____ sizeof(acColor) = _____ 2.
char str[] = \char *p = str; int n = 1000; 请计算
sizeof (str ) = ____________
sizeof ( p ) = ______________ sizeof ( n ) = ______________ 3.UCHAR *pucCharArray[10][10]; typedef union unRec {
ULONG ulIndex; USHORT usLevel[6]; UCHAR ucPos; }REC_S;
REC_S stMax,*pstMax;
四字节对齐方式时: sizeof(pucCharArray) = ______, sizeof(stMax)=_______, sizeof(pstMax)=________,sizeof(*pstMax)=________. 4.
UCHAR *pszTest = \UCHAR aucTest[] = \
请问 sizeof(pszTest) = _____ , sizeof(*pszTest) = ______, sizeof(aucTest) = ______. 5.typedef struct tagTest {
UCHAR ucFlag; ULONG ulLen; }TEST_S;
TEST_S test[10];
四字节对齐方式时: sizeof(TEST_S) = __8___, sizeof(test)___80___. 6.typedef union unHead {
UCHAR aucSrc [6]; struct tagContent {
UCHAR ucFlag[3]; ULONG ulNext;// }Content; }HEAD_S;
32CPU,VC编译环境下:
在强制一字节对齐情况下,请指出sizeof(HEAD_S) = ______7_; 在强制二字节对齐情况下,请指出sizeof(HEAD_S) = __6______; 在强制四字节对齐情况下,请指出sizeof(HEAD_S) = ___8_____; 7. struct BBB {
long lNum;4 char *pcName;4 short sDate;2
char cHa[2];2 short sBa[6];6+2 }*p;
p = 0x100000;
p + 0x1 = 0x_100014___
(unsigned long)p + 0x1 = 0x_100004_____ (unsigned long *)p + 0x1 = 0x100004______ (char *)p + 0x1 = 0x_100004_____ 8.在4字节对齐的情况: typedef struct tagRec {
long lA1; 4 char cA2; 4 char cA3;4 long lA4;4 long lA5;4 } REC_S;
void main(int argc, char *argv[]) {
REC_S stMax ;
printf(\ return; }
输出结果为:
sizeof(stMax)=___20_ 9.struct tagAAA {
unsigned char ucId:1;4 unsigned char ucPara0:2;4 unsigned char ucState:6;8 unsigned char ucTail:4;4 unsigned char ucAvail;4 unsigned char ucTail2:4;4 unsigned long ulData;4 }AAA_S;
问:AAA_S在字节对齐分别为1、4的情况下,占用的空间大小是多少?19 32 10.#pragma pack(4)/*编译选项,表示4字节对齐*/ int main(int argc, char* argv[]) {
struct tagTest1 {
short a;4 char d; 4
long b; 4 long c; 4 16 };
struct tagTest2 12 {
long b; 4 short c; 2 char d;2 long a; 4 };
struct tagTest3 {
short c;4 long b;4 char d; 4 long a; 4 };
struct tagTest1 stT1; struct tagTest2 stT2; struct tagTest3 stT3;
printf(\ return 0; }
#pragma pack()(编译选项结束) 请问输出结果是:____16,12,16 11.union tagAAAA {
struct {
char ucFirst; short usSecond; char ucThird; }half; long lI; }number;
struct tagBBBB {
char ucFirst; short usSecond; char ucThird; short usForth; }half;
struct tagCCCC {
struct {
char ucFirst; short usSecond; char ucThird; }half; long lI; };
在字节对齐为1下,sizeof(union tagAAAA)、sizeof(struct tagBBBB)、sizeof(struct tagCCCC)是____ ____ _____
在字节对齐为4下,sizeof(union tagAAAA)、sizeof(struct tagBBBB)、sizeof(struct tagCCCC)是____ ____ _____
12.以下程序的输出的结果是___________ #pragma pack(4)/*四字节对齐*/ int main(int argc, char* argv[]) {
unsigned char puc[4]; struct tagPIM
unsigned char ucPim1; unsigned char ucData0:1; unsigned char ucData1:2; unsigned char ucData2:3; }*pstPimData;
pstPimData = (struct tagPIM *)puc; memset(puc, 0, 4);
{
//此时内存情况为: // ucPim1(8bits)->puc[0] // // pstPinData->00000000 <-puc[0] //对应puc[1]中的编号:ucData0->8; ucData1->6、7; ucData2->3、4、5 // 编号: 12345678 // 00000000 <-puc[1] // 00000000 <-puc[2] // 00000000 <-puc[3] pstPimData->ucPim1 = 1;
//执行完此步后,内存状况为:
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库C_C++语言笔试面试题目含答案(5)在线全文阅读。
相关推荐: