| 注册
home doc ppt pdf
请输入搜索内容

热门搜索

年终总结个人简历事迹材料租赁合同演讲稿项目管理职场社交

c语言高级面试题

望***3

贡献于2024-02-03

字数:7941

整测试遵循约定:
u       假定程序中必须头文件已正确包含
考虑数类型:
u       char 1字节
u       int 4字节
u       long int 4字节
u       float 4字节
u       double 8字节
u       long double 8字节
u       指针4字节
 
 
1 Consider the following program
#include
static jmp_buf buf
 
main()
{
volatile int b
b 3
 
if(setjmp(buf)0)
{
printf(d b)
exit(0)
}
b5
longjmp(buf 1)
}
The output for this program is

(a) 3
(b) 5
(c) 0
(d) None of the above
2 Consider the following program
main()
{
struct node
{
int a
int b
int c
}
struct node s { 3 56 }
struct node *pt &s
printf(d *(int*)pt)
}
The output for this program is
(a) 3
(b) 5
(c) 6
(d) 7
3 Consider the following code segment
int foo ( int x int n)
{
int val
val 1

if (n>0)
{
if (n2 1) val val *x

val val * foo(x*x n2)
}
return val
}
What function of x and n is compute by this code segment
(a) x^n
(b) x*n
(c) n^x
(d) None of the above
4 Consider the following program
main()
{
int a[5]
int *ptr (int*)(&a+1)
 
printf(d d *(a+1) *(ptr1) )
 
}
The output for this program is

(a) 2 2
(b) 2 1
(c) 2 5
(d) None of the above
5 Consider the following program
void foo(int [][3] )
 
main()
{
int a [3][3] { { 123} { 456}}
foo(a)
printf(d a[2][1])
}
 
void foo( int b[][3])
{
++ b
b[1][1] 9
}
The output for this program is
(a) 8
(b) 9
(c) 7
(d) None of the above
6 Consider the following program
main()
{
int a bc d
a3
b5
cab
d(ab)
 
printf(cd c)
printf(dd d)
 
}
The output for this program is

(a) c3 d3
(b) c5 d3
(c) c3 d5
(d) c5 d5
7 Consider the following program
main()
{
int a[][3] { 123 456}
int (*ptr)[3] a
 
printf(d d (*ptr)[1] (*ptr)[2] )
 
++ptr
printf(d d (*ptr)[1] (*ptr)[2] )
}
The output for this program is

(a) 2 3 5 6
(b) 2 3 4 5
(c) 4 5 0 0
(d) None of the above
8 Consider following function
int *f1(void)
{
int x 10
return(&x)
}
 
int *f2(void)
{
int*ptr
*ptr 10
return ptr
}
 
int *f3(void)
{
int *ptr
ptr(int*) malloc(sizeof(int))
return ptr
}
Which of the above three functions are likely to cause problem with pointers

(a) Only f3
(b) Only f1 and f3
(c) Only f1 and f2
(d) f1 f2 f3
9 Consider the following program
main()
{
int i3
int j
 
j sizeof(++i+ ++i)
 
printf(id jd i j)
}
The output for this program is

(a) i4 j2
(b) i3 j2
(c) i3 j4
(d) i3 j6
10 Consider the following program
void f1(int * int)
void f2(int * int)
void(*p[2]) ( int * int)
 
main()
{
int a
int b
 
p[0] f1
p[1] f2
a3
b5
 
p[0](&a b)
printf(dt dt a b)
 
p[1](&a b)
printf(dt dt 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
}
The output for this program is

(a) 5 5 5 5
(b) 3 5 3 5
(c) 5 3 5 3
(d) 3 3 3 3
11 Consider the following program
void e(int )
 
main()
{
int a
a3
e(a)
}
 
void e(int n)
{
if(n>0)
{
e(n)
printf(d n)
e(n)
}
}
The output for this program is

(a) 0 1 2 0
(b) 0 1 2 1
(c) 1 2 0 1
(d) 0 2 1 1
12 Consider following declaration
typedef int (*test) ( float * float*)
test tmp
type of tmp is

(a) Pointer to function of having two arguments that is pointer to float
(b) int
(c) Pointer to function having two argument that is pointer to float and return int
(d) None of the above
13 Consider the following program
main()
{
char *p
char buf[10] { 12345698}
p (buf+1)[5]
printf(d p)
}
The output for this program is

(a) 5
(b) 6
(c) 9
(d) None of the above
14 Consider the following program
Void f(char**)
 
main()
{
char * argv[] { ab cd ef gh ij kl }
f( argv )
}
 
void f( char **p )
{
char* t
 
t (p+ sizeof(int))[1]
 
printf( s t)
}
The output for this program is

(a) ab
(b) cd
(c) ef
(d) gh
15 Consider the following program
#include
int ripple ( int )
 
main()
{
int num
num ripple ( 3 57)
printf( d num)
}
 
int ripple (int n )
{
int i j
int k
va_list p
 
k 0
j 1
va_start( p n)
 
for ( j {
i va_arg( p int)
for ( i i &i1 )
++k
}
return k
}
The output for this program is

(a) 7
(b) 6
(c) 5
(d) 3
16 Consider the following program
int counter (int i)
{
static int count 0
count count +i
return (count )
}
main()
{
int i j
 
for (i0 i <5 i++)
j counter(i)
}
The value of j at the end of the execution of the this program is

(a) 10
(b) 15
(c) 6
(d) 7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Answer With Detailed Explanation
_____________________________________________________________
Answer 1
The answer is (b)

volatile variable isn't affected by the optimization Its value after the longjump is the last value variable assumed

b last value is 5 hence 5 is printed

setjmp Sets up for nonlocal goto * setjmph*

Stores context information such as register values so that the lomgjmp function can return control to the statement following the one calling setjmpReturns 0 when it is initially called

Lonjjmp longjmp Performs nonlocal goto * setjmph*

Transfers control to the statement where the call to setjmp (which initialized buf) was made Execution continues at this point as if longjmp cannot return the value 0A nonvolatile automatic variable might be changed by a call to longjmpWhen you use setjmp and longjmp the only automatic variables guaranteed to remain valid are those declared volatile

Note Test program without volatile qualifier (result may very)
Answer 2
The answer is (a)

The members of structures have address in increasing order of their declaration If a pointer to a structure is cast to the type of a pointer to its first member the result refers to the first member
Answer 3
The answer is (a)

Non recursive version of the program
int what ( int x int n)
{
int val
int product
product 1
val x
 
while(n>0)
{
if (n2 1)
product product*val
n n2
val val* val
}
}
* Code raise a number (x) to a large power (n) using binary doubling strategy *
Algorithm description
(while n>0)
{
if next most significant binary digit of n( power) is one
then multiply accumulated product by current val
reduce n(power) sequence by a factor of two using integer division
get next val by multiply current value of itself
}
Answer 4
The answer is (c)

type of a is array of int
type of &a is pointer to array of int
Taking a pointer to the element one beyond the end of an array is sure to work
Answer 5
The answer is (b)


Answer 6
The answer is (c)

The comma separates the elements of a function argument list The comma is also used as an operator in comma expressions Mixing the two uses of comma is legal but you must use parentheses to distinguish them the left operand E1 is evaluated as a void expression then E2 is evaluated to give the result and type of the comma expression By recursion the expression

E1 E2 En

results in the lefttoright evaluation of each Ei with the value and type of En giving the result of the whole expression
cab *yields ca*
d(ab) * d b *
Answer 7
The answer is (a)


* ptr is pointer to array of 3 int *
Answer 8
The answer is (c)

f1 and f2 return address of local variable when function exit local variable disappeared
Answer 9
The answer is (c)

sizeof operator gives the number of bytes required to store an object of the type of its operand The operands is either an expression which is not evaluated ( (++i + ++ i ) is not evaluated so i remain 3 and j is sizeof int that is 2) or a parenthesized type name
Answer 10
The answer is (a)

void(*p[2]) ( int * int)
define array of pointer to function accept two argument that is pointer to int and return int p[0] f1 p[1] f2 contain address of function function name without parenthesis represent address of function Value and address of variable is passed to function only argument that is effected is a (address is passed) Because of call by value f1 f2 can not effect b
Answer 11
The answer is (a)


Answer 12
The answer is (c)

C provide a facility called typedef for creating new data type names for example declaration
typedef char string
Makes the name string a synonym for int The type string can be used in declaration cast etc exactly the same way that the type int can be Notice that the type being declared in a typedef appears in the position of a variable name not after the word typedef
Answer 13
The answer is (c)

If the type of an expression is array of T for some type T then the value of the expression is a pointer to the first object in the array and the type of the expression is altered to pointer to T
So (buf+1)[5] is equvalent to *(buf +6) or buf[6]
Answer 14
The answer is (d)


p+sizeof(int) point to argv[2]

(p+sizeof(int))[1] points to argv[1]
Answer 15
The answer is (c)

When we call ripple value of the first argument passed to ripple is collected in the n that is 3 va_start initialize p to point to first unnamed argument that is 5 (first argument)Each call of va_arg return an argument and step p to the next argument va_arg uses a type name to determine what type to return and how big a step to take Consider inner loop
( i i&i1) k++ * count number of 1 bit in i *

in five number of 1 bits is (101) 2
in seven number of 1 bits is (111) 3
hence k return 5

example
let i 9 1001
i1 1000
(i1) +1 i
1000
+1
1 001
The right most 1 bit of i has corresponding 0 bit in i1 this way i & i1 in a two complement number system will delete the right most 1 bit I(repeat until I become 0 gives number of 1 bits)
Answer 16
The answer is (b)

Static variable count remain in existence rather than coming and going each time function is called
so first call counter(0) count 0
second call counter(1) count 0+1
third call counter(2) count 1+2 * count count +i *
fourth call counter(3) count 3+3
fifth call counter(4) count 6+4
sixth call counter(5) count 10+5

文档香网(httpswwwxiangdangnet)户传

《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档

下载文档,方便阅读与编辑

文档的实际排版效果,会与网站的显示效果略有不同!!

需要 10 香币 [ 分享文档获得香币 ]

该文档为用户出售和定价!

购买文档

相关文档

C语言代码大全

 乘法口诀表 #include <stdio.h> #include <conio.h> void main(void) { int i,j,x,y; clrscr(); printf(“\n\n * * * 乘法口诀表 * * * \n\n“); x=9; y=5; for(i=1;i<=9;i++) { gotoxy(x,y); printf(“%2d “,i);

山***1 5年前 上传1760   0

专升本C语言题及答案

C语言精编100题一、单选题1. 由C语言编写的代码程序( )A. 可直接执行 B. 是一个源程序C. 经过编译即可执行 D. 经过编译解释才能执行2. 按照C语言规定的用户标识符命名规则,不能出现在标识符中的是( )A. 大写字母 B. 中划线 C. 数字字符 D. 下划线3. 下列选项中,不能用作标识符的是( ) A. _

文***享 3年前 上传1170   0

(1小时学会C语言51单片机)C语言入门教程

△Victor Hugo 维克多?雨果相信很多爱好电子的朋友,对单片机这个词应该都不会陌生了吧。不过有些朋友可能只听说他叫单片机,他的全称是什么也许并不太清楚, 更不用说他的英文全称和简称了。单片机是一块在集成电路芯片上集成了一台有一定规模的微型计算机。简称为:单片微型计算机或单片机 (Single Chip Computer)。单片机的应用到处可见,应用领域广泛,主要应用在智能

豆***2 4年前 上传742   0

技能高考专题:C语言练习

第1题 (20.0分) 题号:332 难度:难 第3章/*-------------------------------------------------------【程序填空】---------------------------------------------------------功能:求如下表达式:

小***库 3年前 上传621   0

电脑编程 所有C语言题库

试卷编号:2203所属语言:C语言试卷方案:所有C语言题库试卷总分:1220分共有题型:1种一、程序填空 共122题 (共计1220分)第1题 (10.0分) 题号:558 难度:中 第2章/*-------------------------------------------------------【程序填空】-------

小***库 4年前 上传955   0

C语言作业:学通讯录

学生通讯录一、 语言和环境1. 实现语言:C语言。2. 环境要求:devC++。二、 实现功能开发一套学生通讯录C语言系统,具体实现如下功能:1. 打开系统显示欢迎界面,以及功能菜单,用户输入需要操作的功能序号,根据用户选择的需要进行相应界面 如图1所示。图1 功能菜单2. 当用户输入序号1时进入到录入学生信息界面,用户输入学生的姓名,性别,年龄和电话,输入完毕保存学生信息,并

小***库 3年前 上传722   0

c语言实验报告

c语言实验报告  学号:__________    姓名:__________    班级:__________    日期:__________   指导教师:__________    成绩:__________  实验一  上机操作初步和简单的C程序设计  一、 实验目的  1、熟悉C语言运行环境Turbo C++3.0  2、会简单的程序调试  3、熟悉C语言

极***速 11年前 上传795   0

C语言上机题库WORD版

C语言习题集3.11输入'A'~'F'中的一个字母,代表一个十六进制数,将其转换为十进制数,求该数与15的和并输出。输入格式:B输出格式:26#include<stdio.h>int main(void){ char ch; int sum; ch=getchar(); sum=ch-'A'+10+15; printf(“%d\n“,sum);

文***享 3年前 上传882   0

C语言知识点总结

C语言最重要的知识点总体上必须清楚的: 1)程序结构是三种: 顺序结构 、选择结构(分支结构)、循环结构。 2)读程序都要从main()入口, 然后从最上面顺序往下读(碰到循环做循环,碰到选择做选择),有且只有一个main函数。 3)计算机的数据在电脑中保存是以 二进制的形式. 数据存放的位置就是 他的地址. 4)bit是位 是指为0 或者1。 byte 是指字节, 一个字节 =

文***享 3年前 上传616   0

C语言实验报告《指针》

C语言实验报告《指针》  学号:__________    姓名:__________    班级:__________    日期:__________   指导教师:__________    成绩:__________  实验五  指针  一、 实验目的  1、掌握指针的概念、会定义和使用指针变量  2、掌握指向数组的指针变量  3、掌握字符串指针的使用  

D***1 11年前 上传957   0

C语言试题库

C 语言试题库 阅读说明*1 ————为题号A ————为答案-个C程序的执行是从 A)本程序的main函数开始,到main函数结束 B)本程序文件的第-个函数开始,到本程序文件的最后-个函数结束 C)本程序的main函数开始,到本程序文件的最后-个函数结束 D)本程序文件的第-个函数开始,到本程序main函数结束 试题库题目*

z***u 1年前 上传662   0

C语言实验报告《数组》

C语言实验报告《数组》  学号:__________    姓名:__________    班级:__________    日期:__________  指导教师:__________    成绩:__________  实验三  数组  一、 实验目的  1、掌握一维和二维数组的定义、赋值和输入输出  2、掌握字符数组和字符串数组的使用  3、掌握与数组有关的排

我***海 11年前 上传883   0

《高级语言程序设计》实验报告

1.掌握在Visual C++6.0环境下C程序的建立、编辑、编译和执行过程。2.掌握C程序的最基本框架结构,完成简单程序的编制与运行。3.了解基本输入输出函数scanf()、printf ()的格式及使用方法。4.掌握发现语法错误、逻辑错误的方法以及排除简单错误的操作技能。

w***2 2年前 上传441   0

《高级语言程序设计》实验报告

设计一种用单链表存储多项式的结构(每个结点存储一项的系数和指数,类型都为int)并编写一个产生多项式链表的函数和一个实现两个多项式相加和相乘的函数。

留***1 5年前 上传3511   0

C语言论文致谢

C语言论文致谢  在硕士学位论文即将完成之际,我想向曾经给我帮助和支持的人们表示衷心的感谢。首先要感谢我的导师曹计昌教授,他在学习和科研方面给了我大量的指导,并为我们提供了良好的科研环境,让我学到了知识,掌握了科研的方法,也获得了实践锻炼的机会。他严谨的治学态度、对我的严格要求以及为人处世的坦荡将使我终身受益。除此之外,他对我生活的关心和照顾也使得我得以顺利完成研究生的学业。在此祝愿他身体健

自***熟 12年前 上传622   0

C语言实验报告《函数》

C语言实验报告《函数》  学号:__________    姓名:__________    班级:__________    日期:__________  指导教师:__________    成绩:__________  实验四  函数  一、 实验目的  1、掌握函数定义、调用和声明的方法  2、掌握实参和形参之间的传递方式  3、函数的嵌套调用  二、 实

t***g 12年前 上传1361   0

C语言程序设计习题试题集

《C语言程序设计》精品课件试题目录(按住CTRL键点击超链)单项选择题………………………第002页阅读程序题………………………第018页程序填空题………………………第039页编写程序题………………………第070页《高级语言程序设计》课程设计制作小组2007年一、单项选择题导读:单项选择题要求从给出的四个备选答案中,选出一个最符合题意

文***享 1年前 上传5463   0

国开电大《C语言程序设计》答案

形考1在每个C语言程序中都必须包含有这样一个函数,该函数的函数名为(  )。选择一项:A. main 正确恭喜你,答对啦!!B. MAIN C. name D. function .题目2正确获得2.00分中的2.00分 标记题目题干C语言源程序文件的缺省扩展名为(  )。选择一项:A. cpp B. exe C.

3265912 1年前 上传409   1

C语言综合实验2报告

实验报告实验名称 小型学生信息管理系统 实验项目 编写一学生信息管理系统,用来管理学生基本信息及成绩信息专业班级 姓名 学号 指导教师 成绩 日期 一、

文***品 3年前 上传444   0

专升本C语言历年考试题及答案

专升本C语言历年考试题及答案一、单项选择题1. ___D___是合法的用户自定义标识符。A、 b-b B、float C、<fr> D、 _isw 2. 若变量已正确定义并赋值,表达式___B___不符合C语言语法。A、a*b/c; B、3.14%2 C、2, b

文***享 3年前 上传1355   0

C++语言课程设计一迷你高尔夫

C++语言课程设计一迷你高尔夫一、实验内容 玩家通过按下键盘上的上下左右方向键控制球的移动,使其最终到达出口则游戏通关。 要求如下:1、 游戏分成3关,第一关、第二关、第三关界面图如下:第一关第二关第三关2、 启动游戏进入第一关,胜利后进入第二关,如果第三关通关,则游戏重新回到第一关。3、 游戏玩法是通关控制键盘上的上下左右方向键控制球的运动,单击方向键,则球获得一个向该

文***品 3年前 上传608   0

C语言课程设计学生考勤系统

设计任务:C语言课程设计任务书题目:学生考勤系统设计功能:学生考勤系统应包含各班学生的全部信息。每个学生是一条记录,包括姓名、性别、学号、出勤情况等。本系统可模拟考勤过程,记录考勤结果,并能够在课程结束后按照设定的考勤评分标准自动给出每个学生的考勤分数。分步实施:1、 初步完成总体设计,搭好框架,确定人机对话界面,确定函数个数;2、 建立一个文件,将每条记录信息写入文件中并能显示于

文***品 2年前 上传523   0

c语言课程设计总结5篇

c语言课程设计总结5篇c语言课程设计总结(一):  c语言课程设计总结心得  经过一个学期的学习,我对C语言有了必须的了解。C语言是学习计算机科学的基础,作为一名计算机专业学生,掌握C语言更是毋庸置疑。在上课之前,就经常听同学说,C语言很难学,确实,刚开始听课时觉得老师不知所云。但是,发现对后续资料的预习后,前面的疑团都迎刃而解,这让我对C语言的学习更有信心。  计算机最重要的就是上机操

四***廷 3年前 上传1294   0

C语言程序设计说课教案

《C语言程序设计》说课教案从以下方面说明:一、 课程性质、地位二、 教学对象分析及要求三、 课程体系四、 课程的重点、难点及突破五、 教学方法与教学手段六、 学生考核七、 教学计划一、 课程性质、地位 1.课程的性质  《C语言程序设计》课程是高职高专通信类和电子信息类各专业职业素质必修课,旨在培养高职学生运用计算机进行逻辑思维的能力,掌握运用C语言编程来解决岗位

文***享 1年前 上传342   0

NOIP2008提高组初赛(C语言)试题及答案

第十四届(NOIP2008)信息学奥赛联赛提高组C语言初赛试题● ●  全部试题答案均要求写在答卷纸上,写在试卷纸上一律无效  ●●一、 单项选择题 (共10题,每题1.5分,共计15分。每题有且仅有一个正确答案)。1. 在以下各项中,(C  )不是操作系统软件。 A. Solaris   B. Linux    C. Sybase     D. Windows Vista      E

文***享 3年前 上传578   0