关于C的有趣问题
//以下程序是实现小写转大写程序
#include<stdio.h>
void to_upper(char *str)
{
for(;*str !='\0';str++)
{
if(unsigned(*str-'a')<='z'-'a')
*str-='a'-'A';//小写转成大写
}
}
void main()
{
char *str="Are you ready?";
to_upper(str);
printf("%s\n",str);
}
以上程序在编译和连接都通过了,但却得不出结果!!
char *str="Are you ready?";对应的汇编
004010A8 mov dword ptr [ebp-4],offset string "Are you ready?" (00422020)
改正为:
#include<stdio.h>
void to_upper(char *str)
{
for(;*str !='\0';str++)
{
if(unsigned(*str-'a')<='z'-'a')
*str-='a'-'A';//小写转成大写
}
}
void main()
{
char str[]="Are you ready?";
to_upper(str);
printf("%s\n",str);
}
输出:ARE YOU READY?
char str[]="Are you ready?"对应的汇编:
004010A8 mov eax,[string "Are you ready?" (00422020)]
004010AD mov dword ptr [ebp-10h],eax
004010B0 mov ecx,dword ptr [string "Are you ready?"+4 (00422024)]
004010B6 mov dword ptr [ebp-0Ch],ecx
004010B9 mov edx,dword ptr [string "Are you ready?"+8 (00422028)]
004010BF mov dword ptr [ebp-8],edx
004010C2 
相关文档:
Authentication
Login with:New JS-Kit account
Google Friend Connect
Twitter account
FriendFeed account
Yahoo account
Blogspot URL
JS-Kit account
Haloscan account
OpenID
Dear visitor,
Thanks for your interest in C programming.
In this page, you will find a
list of interesting C p ......
这个本来以前也写过的,今天无聊复习下 再写一遍。简单的一塌糊涂,写的不咋地大家见谅哦!有空再加强 嘿嘿!
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <time.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h ......
各位大哥,有清楚GPS接收灵敏度的指标---载噪比C/N, C/No的有何含义,两者有何区别,可以在这里讨论一下。
C/No=10* Log(C/KTB)﹐不包括天線到Correlator的PATH LOSS及LNA等線路引進的噪音﹔而C/N則包括一切噪音。
C是指信號強度﹐K是指波爾 ......
1、有符号变量与无符号变量值的变换
将有符号变量转换为无符号变量,注意负数的转换。
2、数值的交换
//使用临时变量
void Swap1(int &a, int &b)
{
int temp = a;
a = b;
&nbs ......
1.引言
本文的写作目的并不在于提供C/C++程序员求职面试指导,而旨在从技术上分析面试题的内涵。文中的大多数面试题来自各大论坛,部分试题解答也参考了网友的意见。
许多面试题看似简单,却需要深厚的基本功才能给出完美的解答。企业要求面试者写一个最简单的strcpy函数都可看出面试者在技术上究竟达到了怎样 ......