【无标题】

1.以下程序的正确运行结果是( )。(鲁科安全)

int f(int a);

int main(void)

{

    int a = 2,i;

for(i = 0; i < 3; i++)

printf("%4d", f(a));

}

int f(int a)

{

    int b = 0;

    static int c = 3;

b++;

c++;

    return (a+b+c);

}

A. 777 B. 7 10 13 C. 7 9 11 D. 7 8 9

分析:int b=0为局部变量 函数调用结束时释放

2.在一个被调用函数中,关于return语句使用的描述,( )是错误的 (软通动力)

A. 被调用函数中可以不用return语句

B. 被调用函数中可以使用多个return语句

C. 被调用函数中,如果有返回值,就一定要有return语句

D. 被调用函数中,一个return语句可以返回多个值给调用函数

 D

分析:只能返回一个值

3以下程序的运行结果为( ) (鲁科安全)

#include <stdio.h>

#include <string.h>

int SubCount(char *dest, int count)

{

    strcpy(dest, "555");

    count++;

    return 0;

}

int main()

{

    int count = 3;

    char caBuf[8];

    SubCount(caBuf, count);

    printf("%d\n", count);

    return 0;

}

A. 8 B. 4 C. 3 D. 5

 C

4.请问运行Test函数会有什么样的结果?(华辰泰尔)

char *GetMemory(void)

{

    char p[] = "hello world";

    return p;

}

void Test(void)

{

    char *str = NULL;

    str = GetMemory();

    printf(str);

}

 无效的指针,输出不确定

5.分析以下程序,写出运行结果并写出过程 (广域科技)

#include <stdio.h>

#include <stdlib.h>

void getalloc(char *p)

{

    p = (char *)malloc(100);

    strcpy(p, "hello world");

}

int main()

{

    char *str = NULL;

    getalloc(str);

    printf("%s\n",str);

    free(str);

    return 0;

}

 程序报错 

传入getalloc函数的形参为字符串指针,在函数内部修改形参并不能真正的改变传入形参的值

6.下列程序的输出结果是________。(富士安全)

fun(int a, int b, int c)

{

    c = a*b;

}

void main()

{

    int c = 10;

    fun(2,3,++c);

    printf("%d\n", c);

}

 10

主函数定义c为10,然后调用(2,3,++c),c值在这里作为一个实际参数传递到子函数中,子函数的变化对实参值无影响

7.找错题,说明那里错了(恩易物联1,深圳元征信息科技)

void test1()

{

    char string[10];

    char *str1 = "0123456789";

    strcpy( string, str1 );

}

 str1需要11个字节才能存放下,string只有10个

8.下面的代码片段会输出__________ (飞音时代)

void test(void)

{

    char *p = NULL;

    strcpy(p, "hello");

    printf("%s", p);

}

 没有输出

9.sizeof(str); 的值是多少? (21年中航安为)

void Func(char str[100])

{

sizeof(str);

}

 8

10.递归函数最终会结束,那么这个函数一定( );(北京信果科技)

A. 使用了局部变量

B. 有一个分支不调用自身

C. 使用了全局变量或者使用了一个或多个参数

 B

11.程序如下,程序执行后的输出结果是: (中科四平)

int f(int x, int y)

{

    return (y-x)*x;

}

void main()

{

    int a = 3,b=4,c=5,d;

    d=f(f(3,4),f(3,5));

    printf("%d\n", d);

}

 9

分析:d=f(3,6) (6-3)*3=9

12.请判断下面程序输出的值是多少? (信雅达)

int func(int a)

{

    static int b = 0;

    b+=a;

    return b;

}

int main(void)

{

    printf("%d %d\n", func(1)+func(3), func(5));

}

5 9 

func(1)=1 func(3)=4 func(5)=9

13.这段程序的输出是(________) (青岛汉泰)

void f1(int *, int);

void f2(int *, int);

void(*p[2]) (int *, int);   

main()

{

    int a;

    int b;

    p[0] = f1;

    p[1] = f2;

  a=3;

  b=5;

  p[0](&a, b);

    printf("%d\t %d\t", a, b);

    p[1](&a, b);

    printf("%d\t %d\t", a, b);

}

void f1(int * p, int q)

{

    int tmp;

    tmp = *p;

    *p = q;

    q = tmp;

}

void f2(int *p, int q)

{

    int tmp;

    tmp = *p;

    *p = q;

    q = tmp;

}

A. 5 5 5 5 B. 3 5 3 5 C. 5 3 5 3 D. 3 3 3 3

 A

14.有以下程序段, x=7执行后的值为 ( ) (杭州快越科技)

int fun(int x) {

int p;

if(x==0||x==1)

return(3);

    p=x-fun(x-2);

return p;

}

A. 0 B. 2 C. 5 D. 6

 B

分析:7-fun(5)

            7-(5-fun(3))

            7-(5-(3-3))

15.有以下函数,该函数的返回值是:( ) (山东信通电子)

char *fun(char *p)

{

    return p;

}

A. 无确切的值 B. 形参 p 中存放的地址值

C. 一个临时存储单元的地址 D. 形参 p 自身的地址值

 B

分析:p是一个字符型指针变量,返回p值就是p存放的地址值

16.编写strcpy函数 (山东山大电力技有限公司)

已知strcpy 函数的原型是

char *strcpy(char *strDest,const char *strSrc);其中 strDest 是目的字符串,strSrc 是源字符串。

(1)、不调用 C 的字符串库函数,请编写函数 strcpy。

(2)、strcpy 能把 strSr 的内容复制到 strDest,为什么还有 char"类型的返回值?

(3)、strcpy 和 memcpy 的区别。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *myStrcpy(char *strDest, const char *strSrc) {  
    if (strDest == NULL) {  
        return NULL;  
    }  
    while ((*strDest++ = *strSrc++) != '\0') {  

    }  
   
    return strDest - 1; // 注意:由于循环结束后 strDest 指向 '\0' 的下一个位置,所以返回时需要减 1  
  
}  
  
int main() {  
    char src[] = "helloworld";  
    char dest[100]; 
    myStrcpy(dest, src);  
  
    printf("Copied string: %s\n", dest);  
  
    return 0;  
}

17.请实现一个函数,输入一个整数,输出该数二进制表示中的1的个数。例如:把9表示成二进制是1001,有2位是1。因此如果输入9,该函数输出2。(矩阵软件)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int fun(int);
int main(int argc, const char *argv[])
{
	int num;
	printf("输入一个数:");
	scanf("%d",&num);
	printf("该数二进制表示中1的个数:%d\n",fun(num));
	return 0;
}
int fun(int num){
	static int count=0;
	if(num<2){
		if(num==1){
			count++;
		}
		return count;
	}else{
		if(num%2==1){
			count++;
		}
		return fun(num/2);
	}
}

18.请用编写递归算法计算fibinacci数列第1000位的值。斐波拉契数列为1,1,2,3,5,8,13,21,…… (北京凝思软件)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int fbnq(int n);
int main(int argc, const char *argv[])
{
	printf("斐波那契数列第1000位的值是:%d\n",fbnq(1000));
}
int fbnq(int n){
	if(n==1||n==2){
		return 1;
	}else{
		return fbnq(n-1)+fbnq(n-2);
	}
}

19.用 C 语言写一个递归算法求 N!(华辰泰尔) 

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int fun(int);
int main(int argc, const char *argv[])
{
	int N;
	printf("输入数:");
	scanf("%d",&N);
	printf("%d!=%d\n",N,fun(N));
	return 0;
}
int fun(int n){
	if(n==0){
		return 1;
	}else{
	return n*fun(n-1);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值