C语言面试题和答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.什么是编辑器,编译器,源代码,目标代码?

2.编写一个最简单的程序。

答案:void main(void) {} 或

void main(void)

{

}

3.C语言有哪两种存储数值的方式?

答案:变量和常量

4.请写出下列代码的输出内容

#include

int main(void)

{

int a,b,c,d;

a=10;

b=a++;

c=++a;

d=10*a++;

printf("b,c,d:%d,%d,%d",b,c,d); return 0;

}

答:10,12,120

5. 请写出下列代码的输出内容

#include

int a,b;

int main(void)

{

a =

b = 5;

/* Print them, decrementing each time. */

/* Use prefix mode for b, postfix mode for a */

printf("\nPost Pre");

printf("\n%d %d",a--,--b);

printf("\n%d %d",a--,--b);

printf("\n%d %d",a--,--b);

printf("\n%d %d",a--,--b);

printf("\n%d %d\n",a--,--b);

system("PAUSE");

return 0;

}

答案:5 4

4 3

3 2

2 1

1 0

6.请写出下列代码的输出内容

#include

/* Initialize variables. Note that c is not less than d, */

/* which is one of the conditions to test for. */

/* Therefore, the entire expression should evaluate as false.*/

int a = 5, b = 6, c = 5, d = 1;

int x;

int main( void )

{

/* Evaluate the expression without parentheses */

x = a < b || a < c && c < d;

printf("\nWithout parentheses the expression evaluates as %d", x);

/* Evaluate the expression with parentheses */

x = (a < b || a < c) && c < d;

printf("\nWith parentheses the expression evaluates as %d\n", x);

return 0;

}

答案:Without parentheses the expression evaluates as 1

With parentheses the expression evaluates as 0

7.下面表达式的值是多少?

10 % 3 * 3 —(1 + 2)

答案:0

8.请写出下列代码的输出内容

/* Demonstrates function recursion. Calculates the */

/* factorial of a number. */

#include

unsigned int f, x;

unsigned int factorial(unsigned int a);

int main( void )

{

puts("Enter an integer value between 1 and 8: ");

scanf("%d", &x);

if( x > 8 || x < 1)

{

printf("Only values from 1 to 8 are acceptable!");

}

else

{

f = factorial(x);

printf("%u factorial equals %u\n", x, f);

}

return 0;

}

unsigned int factorial(unsigned int a)

{

if (a == 1)

return 1;

else

{

a *= factorial(a-1);

return a;

}

}

9.请写出下列代码的输出内容

/* Demonstrates nesting two for statements */

#include

void draw_box( int, int);

int main( void )

{

draw_box( 4, 9 );

return 0;

}

void draw_box( int row, int column )

{

int col;

for ( ; row > 0; row--)

{

for (col = column; col > 0; col--)

printf("X");

printf("\n");

}

}

答案:XXXXXXXXX

XXXXXXXXX

XXXXXXXXX

XXXXXXXXX

10.用C语言写出冒泡排序。

#include

main()

{ int a[10];

int i,j,t ;

printf("input 10 numbers:");

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

scanf("%d",&a[i]);

printf("\n");

for(j=0;j<=9;j++)

for(i=0;i<=9-j;i++)

if(a[i]>a[i+1])

{t=a[i];a[i]=a[i+1];a[i+1]=t;} printf("the sorted number:\n");

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

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

}

11.在Windows下,写出运行结果。

#include

相关文档
最新文档