首页 > 其他 > 详细

指针和字符串

时间:2020-08-30 21:25:23      阅读:90      评论:0      收藏:0      [点我收藏+]

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

 

int main01()

{

  /*char  ch[]="hello world";

  char*p=ch;

  printf("%s\n",p);//hello world

  printf("%c\n",*p);//h

  printf("%c\n",*(p+1));//e */

 

  char ch[]="hello world";//栈区字符串

  char*p="hello world";//数据区常量区字符串

  char*p1="hello world";

//内存地址相同

  printf("%p\n",p);

  printf("%p\n",p1);

  

  ch[2]=‘m‘;

  //*(p+2)=‘m‘;//err

  //p[2]=‘m‘;//err

  printf("%s\n",ch);//hemlo world

  printf("%s\n",p);//hello world

  return EXIT_SUCCESS;

}

 

int mani(void)

{

//字符串数组

//指针数组   int*arr[3];

//可修改

  /*char ch1[]="hello";

  char ch2[]="world";

  char ch3[]="aoligei";

  char*arr[]={ch1,ch2,ch3};*/

  

//字符串数组;常量字符串,不能修改

  char*arr[]={"hello","world","aoligei"};

  /*for(int i=0;i<3;i++)

  {

    printf("%s\n",arr[i]);//hello world aoligei

    printf("%c\n",arr[i][0]);//h  w  a

  }*/

  

//字符串排序(根据字符串首字母ASCII码)

技术分享图片

 

 

 

  for(int i=0;i<3-1;i++)

  {

    for(int j=0;j<3-1-i;j++)

    {

      if(arr[j][0]>arr[j+1][0])

      {

        chat*temp=arr[j];

        arr[j]=arr[j+1];

        arr[j+1]=temp;

      }

    }

  }

  for(int i=0;i<3;i++)

  {

    printf("%s\n",arr[i]);

  }

  return 0;

}

指针和字符串

原文:https://www.cnblogs.com/wanghong19991213/p/13586582.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!