最近看了些C面试题顺便复习一下C语言,现贴一些出来和大家分享。

 #include <stdio.h>
void main ()
{
int arr[]={,,,,};---------
int *ptr=arr; ---------
*(ptr++)+=; ----------
printf("%d,%d\n",*ptr,*(++ptr)); ---------
}

【解析】:这段代码应该是比较简单的一个面试题,首先在主函数里,定义了一个一维数组,接着ptr被初始化为数组arr的首地址,也就是一二两句一般都没啥问题,但是第三句有可能就会产生分歧了,有人可能认为,根据书中的表达,括号的优先级应该是大于指针大于++大于+=,所以应该是先执行ptr++,然后事实并非如此,此处是需要先赋值,再自加的,也就是第三句代码是被两句代码合二为一了,可分解如下:*ptr=*ptr+123; ptr++;由数组名是数组首元素的地址可知,首元素为6+123=129,而ptr自加一,指向了7所在的地址。第四句代码为printf输出,printf输出是从右向左压栈(有兴趣的朋友可以测试下printf为什么是从右向左压栈输出的:))所以输出时先执行*(++ptr),也就是指针再加一,指向元素8所在的地址,*(++ptr)为取出元素8,此时ptr已经为指向8所在的地址,故*ptr同样为8.

使用VS2012编译如下:

 

an interview question(3)的更多相关文章

  1. an interview question(1)

    声明:本文为博主原创文章,未经博主允许不得转载. 以下是英文翻译: warnning: Copyright!you can't reprint this blog when you not get b ...

  2. Core Java Interview Question Answer

    This is a new series of sharing core Java interview question and answer on Finance domain and mostly ...

  3. shit LeetCode interview Question

    shit LeetCode interview Question https://leetcode.com/interview/1/ 有点晕,啥意思,没太明白,到底是要按什么排序呀? 去掉 标识符 不 ...

  4. JavaScript interview Question - Create a Array with two papameters without using loop!

    JavaScript interview Question - Create a Array with two papameters without using loop! JavaScript - ...

  5. An interview question from MicroStrategy

    去年校招时的一道面试题,觉得蛮有意思,贴出来. Question: Spy start at a, during an interval he moves |b| to right when b &g ...

  6. an interview question(4)

    版权声明:本文为博主原创文章,未经博主允许不得转载. 写这篇博客前请让博主先吐糟下自己的PC. i3+2G内存+开了一上午=C盘剩下0字节+打开VS2012花了半个小时+一晚上的心情不好 吐槽完PC, ...

  7. an interview question(2)

    感觉现在好多面试题还是很注重基础的,今天面试时就遇到这题,回来一查后才知道此题是国内某著名通信公司的一道机试题:) 给定一个数组input[ ],如果数组长度n为奇数,则将数组中最大的元素放到 out ...

  8. Interview Question

    HDS(11.16.2015): How to design an non-stop website like Google or Amazon? What design patterns are y ...

  9. Amazon Interview Question: Design an OO parking lot

    Design an OO parking lot. What classes and functions will it have. It should say, full, empty and al ...

随机推荐

  1. 在线免费生成 <IDEA>全系列 注册码

    body { background: #fff; color: #333; font-family: Consolas, sans-serif; margin: 2em auto; width: 70 ...

  2. JSP以及JSP解析原理

    什么是JSP? JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. JSP这门技术的最大的特点在于,写jsp就像在写htm ...

  3. Java里能用session吗?

    1.Session是服务器端存储的,Js里不能使用. 2.一般Session的实现需要依赖客户端的Cookie来储存一个SessionId,客户端每次请求服务器都会带上这个Cookie,这样服务器端就 ...

  4. com.caucho.hessian.io.HessianProtocolException: is unknown code 解决方案

    问题: Cannot access Hessian remote service at [http://....../remote/syllabusService]; nested exception ...

  5. 利用selector设置ImageButton不同状态下的背景图片

    1.自定义MyButton类 public class MyButton extends Button { //This constructormust be public MyButton(Cont ...

  6. tomcat

    引用:http://blog.csdn.net/nairuohe/article/details/6175243 /etc/tomcat6 - 全局配置 /usr/share/tomcat6/ - 程 ...

  7. [原创]win10 命令行出现问号而且无法chcp 936

    现象: 命令行中中文字符显示为问号,输入chcp 936会提示 invlalid page code. 解决: 设置-区域和语言-时钟,语言和区域-区域-更改位置-管理-非Unicode中所使用的语言 ...

  8. OpenCart中文乱码解决方法

      遇到在列表页面调用部分截取中文内容的时候,被截取的内容有乱码,改数据库的编码没用,后来发现:utf8_substr(strip_tags(html_entity_decode($result['d ...

  9. 关于 K米 —— 的案例分析

    第一部分 调研,评测 评测 下载并使用,描述最简单直观的个人第一次上手体验. 我觉得ktv遥控软件设计的很好,给我带来了很多方便,点歌也不用那么麻烦了跑到台子那里点,调各种音量灯光也是,所以第一次上手 ...

  10. mysql 修改密码

    安装完成后,默认本地登录超级管理员root,密码为空连接服务后(先停止服务,在wamp中运行mysql控制台enterpass:直接回车),执行set password for root@localh ...