C面试时的读程序题ZZ

2024-04-23 03:08
文章标签 面试 程序 zz

本文主要是介绍C面试时的读程序题ZZ,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

C面试时的读程序题ZZ
shury 发表于 2004-12-5 17:50:00

What will print out?
main()
{
        char *p1=“name”;
        char *p2;
        p2=(char*)malloc(20);
        memset (p2, 0, 20);
        while(*p2++ = *p1++);
        printf(“%sn”,p2);

}

Answer:empty string.

What will be printed as the result of the operation below:

main()
{
    int x=20,y=35;
    x=y++ + x++;
    y= ++y + ++x;
    printf(“%d%dn”,x,y);
}

Answer : 5794

What will be printed as the result of the operation below:

main()
{
    int x=5;
    printf(“%d,%d,%dn”,x,x< <2,x>>2);
}

Answer: 5,20,1

What will be printed as the result of the operation below:

#define swap(a,b) a=a+b;b=a-b;a=a-b;
void main()
{
    int x=5, y=10;
    swap (x,y);
    printf(“%d %dn”,x,y);
    swap2(x,y);
    printf(“%d %dn”,x,y);
}

int swap2(int a, int b)
{
    int temp;
    temp=a;
    b=a;
    a=temp;
    return 0;

}

Answer: 10, 5
10, 5

What will be printed as the result of the operation below:

main()
{
    char *ptr = ” Cisco Systems”;
    *ptr++; printf(“%sn”,ptr);
    ptr++;
    printf(“%sn”,ptr);
}

Answer:Cisco Systems
isco systems

What will be printed as the result of the operation below:

main()
{
    char s1[]=“Cisco”;
    char s2[]= “systems”;
    printf(“%s”,s1);
}
Answer: Cisco

What will be printed as the result of the operation below:

main()
{
    char *p1;
    char *p2;
    p1=(char *)malloc(25);
    p2=(char *)malloc(25);

    strcpy(p1,”Cisco”);
    strcpy(p2,“systems”);
    strcat(p1,p2);

    printf(“%s”,p1);

}

Answer: Ciscosystems

The following variable is available in file1.c, who can access it?:

static int average;

Answer: all the functions in the file1.c can access the variable.

WHat will be the result of the following code?

#define TRUE 0 // some code
while(TRUE)
{

    // some code

}

Answer: This will not go into the loop as TRUE is defined as 0.

What will be printed as the result of the operation below:

int x;
int modifyvalue()
{
    return(x+=10);
}
int changevalue(int x)
{
    return(x+=1);
}

void main()
{
    int x=10;
    x++;
    changevalue(x);
    x++;
    modifyvalue();
    printf("First output:%dn",x);

    x++;
    changevalue(x);
    printf("Second output:%dn",x);
    modifyvalue();
    printf("Third output:%dn",x);

}

Answer: 12 , 13 , 13

What will be printed as the result of the operation below:

main()
{
    int x=10, y=15;
    x = x++;
    y = ++y;
    printf(“%d %dn”,x,y);
}

Answer: 11, 16

What will be printed as the result of the operation below:

main()
{
    int a=0;
    if(a==0)
        printf(“Cisco Systemsn”);
        printf(“Cisco Systemsn”);
}

Answer: Two lines with “Cisco Systems” will be printed.
 
 
 

这篇关于C面试时的读程序题ZZ的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/927617

相关文章

python获取指定名字的程序的文件路径的两种方法

《python获取指定名字的程序的文件路径的两种方法》本文主要介绍了python获取指定名字的程序的文件路径的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 最近在做项目,需要用到给定一个程序名字就可以自动获取到这个程序在Windows系统下的绝对路径,以下

基于Python编写自动化邮件发送程序(进阶版)

《基于Python编写自动化邮件发送程序(进阶版)》在数字化时代,自动化邮件发送功能已成为企业和个人提升工作效率的重要工具,本文将使用Python编写一个简单的自动化邮件发送程序,希望对大家有所帮助... 目录理解SMTP协议基础配置开发环境构建邮件发送函数核心逻辑实现完整发送流程添加附件支持功能实现htm

C#控制台程序同步调用WebApi实现方式

《C#控制台程序同步调用WebApi实现方式》控制台程序作为Job时,需同步调用WebApi以确保获取返回结果后执行后续操作,否则会引发TaskCanceledException异常,同步处理可避免异... 目录同步调用WebApi方法Cls001类里面的写法总结控制台程序一般当作Job使用,有时候需要控制

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

python编写朋克风格的天气查询程序

《python编写朋克风格的天气查询程序》这篇文章主要为大家详细介绍了一个基于Python的桌面应用程序,使用了tkinter库来创建图形用户界面并通过requests库调用Open-MeteoAPI... 目录工具介绍工具使用说明python脚本内容如何运行脚本工具介绍这个天气查询工具是一个基于 Pyt

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

Python程序打包exe,单文件和多文件方式

《Python程序打包exe,单文件和多文件方式》:本文主要介绍Python程序打包exe,单文件和多文件方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python 脚本打成exe文件安装Pyinstaller准备一个ico图标打包方式一(适用于文件较少的程

Python程序的文件头部声明小结

《Python程序的文件头部声明小结》在Python文件的顶部声明编码通常是必须的,尤其是在处理非ASCII字符时,下面就来介绍一下两种头部文件声明,具有一定的参考价值,感兴趣的可以了解一下... 目录一、# coding=utf-8二、#!/usr/bin/env python三、运行Python程序四、

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失