测试题

一:填空(28)

1.2

struct AA{

        char a;

     char b[2];

     short c;

          int d;

          };  

 请问sizeofstruct AA)是___12___

 2. (2 )struct BB{

char a;

short b[2];

char c;

int d;

};

请问sizeofstruct BB)是__12____

 

   3. 6分)  

   int *p = NULL;

       int main()

       {

int i = 3;

static int a = 5;

int *p1= NULL;

p = &a;

*p = i;

p1 = (int *)malloc(5 *sizeof(int));

i++;

 

printf(%d, %d , a, i);

return 0;

       }

32位系统中,内存分为:数据域,栈,堆等。则指针变量pp1所指向的区域分别存储在(数据域),();变量ia分别存储于(),(数据域)printf打印的结果(3),(4);

 

 

4.2分)const的作用,至少两种?1修饰函数参数,表明此参数不可更改 2修饰普通变量,表明此变量不可更改

3修饰指针变量(分两种)

5. (2)  static的用法,至少两种?1修饰一个变量或者函数只能在本文件中使用2修饰一个变量存储在静态数据区(1 限定变量作用域 2设置变量的存储域)

 

6.4分)1定义一个34int类型元素数组;int a[4][3];

            2)一个指向函数的指针,该函数有一个void指针参数并返回一个void型指针;void* (*p)(void*);

 

  7.4分)32位系统中char*p = NULLint a[10] = {0};假设    int  a[10]变量的起始地址是0x10000;指针变量(本身)的地址是0x20000char *p = (char *)a; 则:

       p+1值(0x10001); &p+1值:(0x20004);//判断的时候要根据指针所指向数据的类型来判断

a+1 0x10004;  &a+1 0x10028);

 

8.(2)写出float x零值的比较( #define MIN 0.000001; if(x >= -MIN && x <= MIN); )。

 

9.(2)使用宏定义写出int类型最大值。#define INT_MAX  (unsigned int )-1 >> 1

 

10.(2)以下程序是否有误,如果无误,请写出执行次数(1  )。

int x = -1;

do{

x = x * x;

}while(!x);

 

 

 

 

二:判断(共10分)

11分)#include<stdio.h>  

int main(void) {     

char *ptr = "Linux";   错,Linux”在文字常量区不能被修改

*ptr = 'T';      

printf("  [%s]  ", ptr);      

return 0; 

}.  

程序输出 Tinux  

21分)定义一个指针变量,该指针变量指向一个具10整型指针元素的数组是 int **array[10]

31分)以下都是正确的标识符:Char, Short, If,CASE.  对(关键字是系统定义的,标示符是用户自己定义的)

41分)有语句char str1[10],str2[10]={"china"};则能将字符  china赋给数组str1的正确语句是strcpy(str2,str1) 错(反了)

  5.1分)在大端系统中,int类型的1内存中存储的是0x1  高字节。

  6.1分)有数组定义inta[2][3] = {{1}, {2,3}};a[0][1]的值0.

  7.1分)声明函数int fun(int a[10]);a表示一维数组变量名。错(数组作为一个函数的参数,在没有分配空间的时候a只表示的只是一个指针)而在函数里面定义int a[10],a是一个常量

  8.1分)char *p = hello,  char str[] = hello;表示指针变量pstr都指向文字常量hello错(前面的hello不可以改变,是文字常量,后面的在栈里面,把文字常量区里的“hello”copy到数组里面)

  91分)程序的局部变量都存放在栈中。(静态局部变量)

 101分)switchc)语句中c可以是int float char long   类型。

 

三:(36语法及分析

1.2)写一个宏,求之中比较大的数:_#define MAX  (a) > (b)? a:(b)______.

 

2. 2分)写一个宏判断一个变量是不是无符号数:_#define  IS_UNSIGNDE(value) ___value > 0? (~value > 0?1;0) : 0

3.2分)下面的语句输出的结果是__answer不确定,*p4__________,在可移植操作系统中有什么问题___不同的操作系统answer的值会不一样_____

#include <stdio.h>

int *p = NULL;

int func ( void ) {

static int counter = 1;

   P = &counter;

return counter++;

}

int main ( void ) {

int answer;

answer = func() - func()*func();

printf("%d, %d ",answer, *p);

return 0;

}

 

 

4.2分)下面函数定义有没有错误或者漏洞?如果有,如何修改?

#include <stdio.h>

void showArray( int array [10] ) {  传递过来的数组或字符串可以任意长度,系统会为array[10]根据传递过来的长度分配空间大小,注意:array只是一个指针,sizeof(array)永远等于4,写成array[10],就相当于声明array为指针,array【10】= int* array!也可以写成array【】! 传递过来的必须是指针!!!!!!

int i;

for (i = 1; i< 10; i+=1)  i的值不确定,因为传过来的数组元素个数不确定

if ( array[i] >10 ) 

printf("%d ",array[i]);

}  

5.2分)下面函数定义有没有错误或者漏洞?如果有,为什么,如何修改?            int main(){            char a[5];   char a[6];            char *str = a;            strcpy(str,"hello");            printf(str);   printf(%s ,str);           return 0;            }

6.2分)请问下面的代码的输出结果是2,0

#include <stdio.h>

int main ( void ) {

int i = 6;

int a[5] = {1,2,3,4,5};

char * p = (char * )(&a +1);//移动了25个字节

printf("%d,  %d",*(a+1),*(p-1));

}

7.2分)请问下面的代码的输出结果是

 int main(){

int a[6],*i,*p=a,*t=a;

printf("qing shu ru shu ju: ");

for(i=a;i<a+6;i++){

scanf("%d",i);

}

        for(i=a;i<a+6;i++){

  *p=*i+*t;

  printf("%4d",*p);

  }

 }

 输入:1 2 3 4 5 6

 输出:_2 3 4 5 6 7______________

82分)请问下面的代码的输出结果是

int main ( void ) {

unsigned int a = 6;

int b = - 20;

(a+b)>0?puts(">0"):puts("<=0");

}

 

   9.2

#define N 2

     #define NTI(n) N*n + n

int sum = N * NTI(N + 1);

sum为多少12)。

10.4分)写出下列程序输出结果(  )

#include <stdio.h>

int count = 3; 

int main() 

int i, sum, count = 2; 

for(i = 0, sum = 0; i < count; i += 2,count++) 

static int count = 4; 

count++; 

if(i % 2 == 0) 

extern int count; 

count++; 

sum += count; 

sum += count; 

printf("%d, %d ", count, sum);  4 20

 

return 0; 

}

 

 

 

11.6分)写出下列程序执行结果 ( )。(注,此处按行评判给分)

#include <stdio.h>

#include <string.h>

void func(char str[50])  

{  

 printf("%d, %d ", sizeof(str), strlen(str)); 50,10 4 9

}  

int main()  

{  

 char stra[] = "HelloWorld";  

 char *strb = stra;  

printf("%d, %d ", sizeof(stra), sizeof(strb++));11,11  11 4

 

 func(++strb); 

printf("%d, %d ", sizeof(strb), strlen(strb++));4,10  4 9

 return 0;  

12.4)写出下列程序输出结果()0 1 2 0 9

int func(int n)  

{  

   int k = 1;  

   if(n > 0)  

   {  

 k += func(--n);  

printf(%d, n);  

k += func(--n);  

   }  

   return k;  

}  

int main()  

{  

 int a = 3;  

 printf(%d , fun(a)); 

 return 0;  

}  

 

13.(4)写出下列程序输出结果()0 0 5 0

#include <stdio.h>

struct SC{int a,b,c;};  

struct SD{int a,b,c,d;};  

int main()  

{  

 struct SC c1[] = {{3}, {4}, {5}, {6}};  

 struct SD *c2 = (struct SD*)c1 + 1;  

 printf("%d,%d,%d,%d ",c2->a,c2->b,c2->c,c2->d); 

 return 0;  

}  

 

 

 

 

 

原文地址:https://www.cnblogs.com/siguoya/p/3467856.html