c语言高级面试题


    整测试遵循约定:
    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(); pr...

    5年前   
    1760    0

    专升本C语言题及答案

    C语言精编100题一、单选题1. 由C语言编写的代码程序( )A. 可直接执行 B. 是一个源程序C. 经过编译即可执行 D. 经过编译解释才能执行2. 按照C语言规...

    3年前   
    1169    0

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

    △Victor Hugo 维克多?雨果相信很多爱好电子的朋友,对单片机这个词应该都不会陌生了吧。不过有些朋友可能只听说他叫单片机,他的全称是什么也许并不太清楚, 更不用说他的英文全称和简称了。...

    4年前   
    741    0

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

    第1题 (20.0分) 题号:332 难度:难 第3章/*----------------------------------------------...

    3年前   
    619    0

    电脑编程 所有C语言题库

    试卷编号:2203所属语言:C语言试卷方案:所有C语言题库试卷总分:1220分共有题型:1种一、程序填空 共122题 (共计1220分)第1题 (10.0分) 题号:558 ...

    4年前   
    953    0

    C语言作业:学通讯录

    学生通讯录一、 语言和环境1. 实现语言:C语言。2. 环境要求:devC++。二、 实现功能开发一套学生通讯录C语言系统,具体实现如下功能:1. 打开系统显示欢迎界面,以及功能菜单,用户输入...

    3年前   
    720    0

    c语言实验报告

    c语言实验报告  学号:__________    姓名:__________    班级:__________    日期:__________   指导教师:__________    成...

    11年前   
    792    0

    C语言上机题库WORD版

    C语言习题集3.11输入'A'~'F'中的一个字母,代表一个十六进制数,将其转换为十进制数,求该数与15的和并输出。输入格式:B输出格式:26#include<stdio.h>int main...

    3年前   
    877    0

    C语言试题库

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

    1年前   
    660    0

    C语言知识点总结

    C语言最重要的知识点总体上必须清楚的: 1)程序结构是三种: 顺序结构 、选择结构(分支结构)、循环结构。 2)读程序都要从main()入口, 然后从最上面顺序往下读(碰到循环做循环,碰到选...

    3年前   
    612    0

    C语言实验报告《指针》

    C语言实验报告《指针》  学号:__________    姓名:__________    班级:__________    日期:__________   指导教师:__________ ...

    11年前   
    953    0

    C语言实验报告《数组》

    C语言实验报告《数组》  学号:__________    姓名:__________    班级:__________    日期:__________  指导教师:__________  ...

    11年前   
    881    0

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

    1.掌握在Visual C++6.0环境下C程序的建立、编辑、编译和执行过程。2.掌握C程序的最基本框架结构,完成简单程序的编制与运行。3.了解基本输入输出函数scanf()、printf ()...

    2年前   
    438    0

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

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

    5年前   
    3508    0

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

    形考1在每个C语言程序中都必须包含有这样一个函数,该函数的函数名为(  )。选择一项:A. main 正确恭喜你,答对啦!!B. MAIN C. name D. function .题目2正确...

    1年前   
    405    1

    C语言综合实验2报告

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

    3年前   
    441    0

    C语言实验报告《函数》

    C语言实验报告《函数》  学号:__________    姓名:__________    班级:__________    日期:__________  指导教师:__________  ...

    12年前   
    1357    0

    C语言论文致谢

    C语言论文致谢  在硕士学位论文即将完成之际,我想向曾经给我帮助和支持的人们表示衷心的感谢。首先要感谢我的导师曹计昌教授,他在学习和科研方面给了我大量的指导,并为我们提供了良好的科研环境,让我...

    12年前   
    622    0

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

    《C语言程序设计》精品课件试题目录(按住CTRL键点击超链)单项选择题………………………第002页阅读程序题………………………第018页程序填空题………………………第039页编写程序题…………...

    1年前   
    5453    0

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

    C++语言课程设计一迷你高尔夫一、实验内容 玩家通过按下键盘上的上下左右方向键控制球的移动,使其最终到达出口则游戏通关。 要求如下:1、 游戏分成3关,第一关、第二关、第三关界面图如下:第一关...

    3年前   
    608    0

    文档贡献者

    望***3

    贡献于2024-02-03

    下载需要 10 香币 [香币充值 ]
    亲,您也可以通过 分享原创文档 来获得香币奖励!
    下载文档

    该用户的其他文档