【发布时间】:2010-09-12 23:30:06
【问题描述】:
// ExampleCodes.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
#include<iostream>
using namespace std;
char* stringReverse(char* s)
{
char temp, *p,*q;
q = s;
while( *(++q));
for( p = s; p < --q; p++)
{
temp = *p;
*p = *q;
*q = temp;
}
return s;
}
int _tmain(int argc, _TCHAR* argv[])
{
stringReverse("StringReverse");
return 0;
}
【问题讨论】:
-
将源代码缩进四个空格以使其正确显示。
-
不应该编译器至少给你一个关于将 const char* 传递给 char* 参数的警告。
-
你好像不小心漏掉了你的问题。
-
@Alexander Rafferty:C 中字符串文字的类型是
char [],它衰减为char *(尽管它们是不可修改的)。这是因为字符串文字早于const关键字。
标签: c++