字符指针和整数指针(++) [英] Character pointers and integer pointers (++)

查看:97
本文介绍了字符指针和整数指针(++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个指针,

  char * str1; 
int * str2;

如果我看两个指针的大小,让我们假设

  str1 = 4个字节
str2 = 4个字节


b $ b

str1 ++将增加1个字节,但如果str2 ++将增加4个字节。



这是什么概念?

解决方案

在提供的场景中简单:




  • 1字节长

  • int(在您的平台中)为4字节长



< > ++ 运算符按指针类型的大小递增指针。


I have two pointers,

char *str1;
int *str2;

If I look at the size of both the pointers let’s assume

str1=4 bytes
str2=4 bytes

str1++ will increment by 1 byte, but if str2++ it will increment 4 bytes.

What is the concept behind this?

解决方案

Simple, in the provided scenario:

  • char is 1 byte long
  • int (in your platform) is 4 bytes long

The ++ operator increments the pointer by the size of the pointed type.

这篇关于字符指针和整数指针(++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆