奇怪的c输出

来源:百度知道 编辑:UC知道 时间:2024/05/29 20:32:46
#include<stdio.h>
#include<iostream>
void main()
{
void copy_string (char *from,char *to);
char from[]="i am a teacher";
char to[]="you are a student";
printf("string a=%s\nstring b=%s\n",from,to) ;//1:i am a teacher
//2:you are a student
printf("copy string a to string b:\n"); //3:copy string a to string b:
copy_string(from,to);
printf("string a=%s\nstring b=%s\n",from,to) ;//6:i am a teacher
//7:i am a teacher
printf("from 的地址%s\n",&from); //8:!!!输出的是from数组的内容
printf("from 的地址%s\n",from); //9:输出的是from数组的内容

system("pause");
};
void copy_string(char* from,char *to)//传给*from *to的是from 和 to数组的首地

你这里地址输出干嘛用%s啊,又没意义,修改成%d
printf("from 的地址%d\n",&from); //8:!!!输出的是from数组的内容

楼主把4个输出地址处的%s修改为%x后,看看结果,再好好想想,或许能明白了

#include<stdio.h>
#include<iostream>
void main()
{
void copy_string (char *from,char *to);
char from[]="i am a teacher";
char to[]="you are a student";
printf("string a=%s\nstring b=%s\n",from,to) ;//1:i am a teacher
//2:you are a student
printf("copy string a to string b:\n"); //3:copy string a to string b:
copy_string(from,to);
printf("string a=%s\nstring b=%s\n",from,to) ;//6:i am a teacher
//7:i am a teacher
printf("from 的地址%x\n",&from); //8:!!!输出的是from数组的内容
printf("from 的地址%x\n",from); //9:输出的是from数组的内容

system("pause");
};
void copy_string(char* from,char *to)//传给*from *to的是from 和 to数组的首地址
{
int