从指针 字符串

指针

``#include <stdio.h>

int main() {
int num1 = 100;
int num2 = 200;
int num3 = 300;
int *p_num1 = &num1;
int *p_num11;
int *p_num11;
int *p_num2 = &num2;
printf(“the num1 is %d\n”,num1);
printf(“the pointer of num1 is %p\n”,&num1);
printf(“the pointer of num1 is %p\n”,&num2);
printf(“the pointer of num1 is %p\n”,&num3);
printf(“the type of int size is %ld\n”, sizeof(int));
printf("------------------------------------------\n");
printf(“the num1 is %d by p_num1\n”, *p_num1);
printf(“the pointer is %p\n”, p_num1);
printf(“the pointer of p_num1 is %p\n”, &p_num1);
p_num11 = p_num1;
printf(“the num1 is %d by p_num11\n”, *p_num11);
*p_num1 = 1000;
printf(“the num1 is %d\n”, num1);
printf(“the num1 is %d by p_num1\n”, *p_num1);
printf(“the num1 is %d by p_num11\n”, *p_num11);
*p_num2 = 2000;
printf(“the num1 is %d by p_num2\n”, *p_num2);
p_num2 = p_num11;
printf(“the num1 is %d by p_num1\n”, *p_num2);
printf("------------------------------------\n");
num1 = *p_num1 + 1;

  *p_num1 = *p_num1 + 1;
  num1++;
  *p_num1 = *p_num1 + 1;

  printf("the num1 is %d\n", num1);
  printf("the num1 is %d by p_num1\n", *p_num1);
  printf("------------------------------------\n");
  printf("the num is %d by p_num1 + 2 \n",*(p_num1 + 2));
  printf("the value (p_num[2]) is %d\n", p_num1[2]);
  p_num1 = &num1;
  p_num2 = &num2;
  printf ("the dist of p_num1 and p_num2 is %ld\n",p_num2 - p_num1);
  printf ("the dist of p_num1 and p_num2 is %ld\n",(long)p_num2 - (long)p_num1);
  printf ("------------------------------------------------------\n");
  p_num2++;
  printf ("the p_num2 is %p\n", p_num2);
  printf ("the value of *p_num2 is %d\n", *p_num2);

}


字符串

```c
#include <stdio.h>
#include <string.h>

int main() {
        char str[] = "hello world";
        printf("the str = %s\n",str);
        printf("the pointer is %p\n",str);
        str[0] = 'H';
        str[6] = 'W';
        printf("the changde str = %s\n",str);
        printf("the length of str is %d\n",strlen(str));

        char str2[] = "hello\0 world";
        printf("the str2 = %s\n",str2);
        printf("the pointer is %p\n",str2);
        printf("the world of str2 = %s\n",&str2[0]);
        printf("the world of str2 = world by %s\n",(str2+6));

        char str3[] = {'h','e','l','l','o','\0'};
        printf("the str3 = %s\n",str3);
        printf("the pointer of str3 is %p\n",str3);

        char *p_str = str;
        printf("the str =%s\n by p_str\n",p_str);


}
~    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值