关于indexof的用法法

关于c++中sizeof用法和数组指针问题_百度知道
关于c++中sizeof用法和数组指针问题
int arr1[]={1,2,3};//定义一个含有三个元素的数组 int *source=arr1;//定义一个int指针指向arr1的第一个元素 size_t sz1=sizeof(a哗肠糕段蕹灯革犬宫华rr1);//sz1输出等译12 size_t sz2=sizeof(*source);//sz2等于4为什么会这样子???求高人解释~~
提问者采纳
sizeof(arr1),arr1是哗肠糕段蕹灯革犬宫华数组,arr1里面是int变量 占据4个字节,所以3个变量占据12个字节。int *source ,source是一个指针,若是sizeof(source)之后你会发现是4 因为所有的指针都是大小为4*source是指针所指向的元素,int类型 占据4个字节 所以等于4
如果这样写size_t sz3=sizeof(*arr1);//sz3为什么又等于4呢?是因为*arr1是一个指针?我就是不理解*arr1表示的啥
arr1是数组名同时也是数组首元素的地址,相当于一个指针,*是取值运算符,因此*arr1其实是数组的首元素,还是一个int变量所以结果还是4
提问者评价
谢谢,原来*arr1还是表示首元素
其他类似问题
按默认排序
其他7条回答
sizeof()这个函数,里面是指针,结果都为4size_t sz1=sizeof(arr1);&哗肠糕段蕹灯革犬宫华#47;/sz1输出等译12因为一个int型占4个字节,所以arr1里面有三个元素,所以是12sizeof得到的是其在内存中占的字节数指针是用来存放地址的,它等于计算机内部地址总线的宽度。所以在32位计算机中,一个指针变量的返回值必定是4希望能到你。。。
size_t sz1=sizeof(arr1);//sz1输出等译12里面写得是arr1,arr1不也是一个指向首元素的指针吗?还有如果这样写size_t sz3=sizeof(*arr1);//sz3为什么又等于4呢?是因为*arr1是一个指针?
数组的sizeof值等于数组所占用的内存字节数指针都是4哦。。。。。。
sizeof(数组名)求的是整个数组的大小,即元素类型的大小乘以元素个数source是一个指针变量,其存放的是地址,而*source的值是数组arr1的首地址,32位机的地址都是4个字节
size_t sz1=sizeof(arr1)是数组大小,但是sizeof返回不是个数,而是大小,以字节为单位。size_t sz2=sizeof(*source);返回第一个数组值得大小。
arr1的类型是3个元素的整型数组,为3*4 =12个字节*source类型为整型元素,位4个字节
是保存对象名字所在的空间的大小.和实际存值的大小无关. source 是个int类型的指针
sizeof(arr1)是必须为12了,否则需要释放空间的时候连系统都不知道有多大了。。跟new出来的应该一样吧
arr1的类型是int [],是数组,你赋的值有三个int的,所以是3*4=12*source的类型是int ,占有四个字节。
数组指针的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁关于a lack of 的用法的一题,请解释。
关于a lack of 的用法的一题,请解释。
Scientists have again and again warned us that ----certain kinds of food is dangerous ,especially for children,because without a balanced diet ,their bodies can,t grow properly.A lacking of B.lack C.the lack D.a lack of .
答案我知道选D,可为什么不选B呢,请问a lack of 的用法。
这里that后是一个宾语从句
需要名词作主语 如果选lack
则后面怎么能加certain kinds of food 这一名词短语呢?
其他回答 (2)
lack of 是缺少的意思,固定搭配, B没有介词呀例句A lack of logic.&缺乏逻辑的A lack of money.&缺乏金钱A lack of trust.&缺少信任Habitual lack of care.&疏忽,轻忽习惯性的缺乏关心Lack of muscle tone.&肌弛缓肌肉张力不足Lack of religious belief.&缺乏宗教信仰
lack of 的用法我知道,可是为什么+个a 呢,那么a lack of 又是什么?
lack 做动词可以及物lack 作名词要加of作名词时 a 和 the 都可以加,一个特指,一个泛指
&adj. 缺少
例句与用法
1. The main impediment to growth was a lack of capital.
影响发展的主要障碍是缺乏资本.
2. That shows&a lack of common sense.
那表示缺乏常识。
3. MYTH: Conflict means a lack of love.
传说:有了矛盾表示爱已消失。
B 和C 缺少介词 of
A 多了介词 of
可B 的lack 不也是缺乏的意思吗他作动词的话不也是。
不及物动词接宾语要加介词
相关知识等待您来回答
外语领域专家这个是我写的类
package com.traffic.rest.data.
import java.util.L
import javax.xml.bind.annotation.XmlA
import javax.xml.bind.annotation.XmlE
import javax.xml.bind.annotation.XmlRootE
@XmlRootElement(name="rtime")
public class RTime {
@XmlAttribute
@XmlElement
private List&TimeSegment& segmentL
public String getTs() {
public void setTs(String ts) {
public List&TimeSegment& getSegmentList() {
return segmentL
public void setSegmentList(List&TimeSegment& segmentList) {
this.segmentList = segmentL
package com.traffic.rest.data.
import javax.xml.bind.annotation.XmlA
import javax.xml.bind.annotation.XmlE
import javax.xml.bind.annotation.XmlRootE
@XmlRootElement
public class TimeSegment {
@XmlAttribute
@XmlElement
@XmlElement
@XmlElement
public byte getVol() {
public void setVol(byte vol) {
this.vol =
public byte getSpd() {
public void setSpd(byte spd) {
this.spd =
public byte getCgt() {
public void setCgt(byte cgt) {
this.cgt =
public int getId() {
public void setId(int id) {
public String toString() {
String s = "id:" + this.id + ",vol:" + this.vol +",speed:" + this.spd +",congest:" +this.
当我运行时,出现如下错误,但是如果我去掉所有的get方法,就可以得到,请问这是什么问题,谢啦
javax.ws.rs.WebApplicationException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 6 counts of IllegalAnnotationExceptions
Class has two properties of the same name "segmentList"
this problem is related to the following location:
at public java.util.List com.traffic.rest.data.bean.RTime.getSegmentList()
at com.traffic.rest.data.bean.RTime
this problem is related to the following location:
at private java.util.List com.traffic.rest.data.bean.RTime.segmentList
at com.traffic.rest.data.bean.RTime
Class has two properties of the same name "ts"
this problem is related to the following location:
at public java.lang.String com.traffic.rest.data.bean.RTime.getTs()
at com.traffic.rest.data.bean.RTime
this problem is related to the following location:
at private java.lang.String com.traffic.rest.data.bean.RTime.ts
at com.traffic.rest.data.bean.RTime
Class has two properties of the same name "cgt"
this problem is related to the following location:
at public byte com.traffic.rest.data.bean.TimeSegment.getCgt()
at com.traffic.rest.data.bean.TimeSegment
at private java.util.List com.traffic.rest.data.bean.RTime.segmentList
at com.traffic.rest.data.bean.RTime
this problem is related to the following location:
at private byte com.traffic.rest.data.bean.TimeSegment.cgt
at com.traffic.rest.data.bean.TimeSegment
at private java.util.List com.traffic.rest.data.bean.RTime.segmentList
at com.traffic.rest.data.bean.RTime
Class has two properties of the same name "id"
this problem is related to the following location:
at public int com.traffic.rest.data.bean.TimeSegment.getId()
at com.traffic.rest.data.bean.TimeSegment
at private java.util.List com.traffic.rest.data.bean.RTime.segmentList
at com.traffic.rest.data.bean.RTime
this problem is related to the following location:
at private int com.traffic.rest.data.bean.TimeSegment.id
at com.traffic.rest.data.bean.TimeSegment
at private java.util.List com.traffic.rest.data.bean.RTime.segmentList
at com.traffic.rest.data.bean.RTime
Class has two properties of the same name "spd"
this problem is related to the following location:
at public byte com.traffic.rest.data.bean.TimeSegment.getSpd()
at com.traffic.rest.data.bean.TimeSegment
at private java.util.List com.traffic.rest.data.bean.RTime.segmentList
at com.traffic.rest.data.bean.RTime
this problem is related to the following location:
at private byte com.traffic.rest.data.bean.TimeSegment.spd
at com.traffic.rest.data.bean.TimeSegment
at private java.util.List com.traffic.rest.data.bean.RTime.segmentList
at com.traffic.rest.data.bean.RTime
Class has two properties of the same name "vol"
this problem is related to the following location:
at public byte com.traffic.rest.data.bean.TimeSegment.getVol()
at com.traffic.rest.data.bean.TimeSegment
at private java.util.List com.traffic.rest.data.bean.RTime.segmentList
at com.traffic.rest.data.bean.RTime
this problem is related to the following location:
at private byte com.traffic.rest.data.bean.TimeSegment.vol
at com.traffic.rest.data.bean.TimeSegment
at private java.util.List com.traffic.rest.data.bean.RTime.segmentList
at com.traffic.rest.data.bean.RTime
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:151)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:289)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1029)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 6 counts of IllegalAnnotationExceptions
问题补充:就是说
private List&TimeSegment& segmentL&
@XmlElement&&&&&&&
public String getTs() {&
public void setTs(String ts) {&
&&& this.ts =&
wkshippou 写道我擦,标注放在get方法上啊。。。
我擦,标注放在get方法上啊。。。
已解决问题
未解决问题15911人阅读
昨天突然被一位朋友问到了关于文件结尾的程序问题。在用feof()判断文件时,复制会多产生一个字符。
这个问题在大一的时候,老师上课就强调过,但那时只是模糊的记得个大概,记得这个函数如果用的不对就是会出现问题,解决是要先读一下,然后再判断,具体的什么还真实忘了。而且平常经常用的EOF,所以这个问题自己并没有一个特别好的概念。
现在写的C语言多了,应该能理解这个问题存在的原因。所以就在网上找了好多关于这个问题的解释,一看还真不少,但是好多都说的不清除,让人看完后,感觉默默糊糊的。但是还是在其中学到了不少的知识。现在就把我的理解给写出来,希望都能互相学习下。
查看 stdio.h 可以看到如下定义:
#define &EOF &(-1)
#define &_IOEOF &0x0010&#define &feof(_stream) &((_stream)-&_flag & _IOEOF)
由此可以看出,这两种方式的原理是不同的。
在这里先说下EOF和feof()这个两个宏定义,在我们学的课本中有这样的描述。
EOF是不可输出字符,因此不能在屏幕上显示。由于字符的ASCII码不可能出现-1,因此EOF定义为-1是合适的。当读入的字符值等于EOF时,表示读入的已不是正常的字符而是文件结束符,但这适用对文本文件的读写。在二进制文件中,信息都是以数值方式存在的。EOF的值可能就是所要处理的二进制文件中的信息。这就出现了需要读入有用数据却被处理为&文件结束&的情况。为了解决这个问题,C提供了一个feof()函数,可以用它来判断文件是否结束。feof(fp)用于测试fp所指向的文件的当前状态是否为&文件结束&。如果是,函数则返回的值是1(真),否则为0(假)。
说了这两个的定义,肯定还对二进制文件和文本文件的区别有些模糊(唉,因为我当时就对这些搞不懂),那现在就回顾下这两个文件的概念。C语言支持的是流式文件,它把文件看作由一个一个的字符(字节)数据组成的序列。根据数据的组织和操作形式,可以分为ASCII文件和二进制文件。
ASCII文件又称为文本文件,它是在一个字节的存储单元上存放一个字符(在外存中存放的是该字符的ASCII码,每个字符将占一个字节)。
二进制文件是把内存中的数据按其在内存中的存储格式在磁盘上原样保存。&
对字符而言,由于其外存存储格式和内存表示格式相同,所以,在外存上也存放每个字符的ASCII码。
但是说EOF只能用于文本文件,其实不然,这点不是特别的准确,还要看定义的变量的类型。
下面这段程序对文本文件和二进制文件都可以:
while((c=fgetc(fp)) != EOF){printf("%X/n", c);&}如果读到了FF,由于c定义为int型,所以实际上c=0x000000FF,不等于EOF(-1=0xFFFFFFFF),因此不会误判为文件结尾。
但是如果把c定义为char类型,就有可能产生混淆了。while((c=fgetc(fp)) != EOF){printf("%X/n", c);&}因为文本文件中存储的是ASCII码,而ASCII码中FF代表空值(blank),一般不使用,所以如果读文件返回了FF,说明已经到了文本文件的结尾。但是如果是二进制文件,其中可能会包含FF,因此不能把读到EOF作为文件结束的条件,此时只能用feof()函数。
在VC里,只有当文件位置指针(fp-&_ptr)到了文件末尾,然后再发生读/写操作时,标志位(fp-&_flag)才会被置为含有_IOEOF。然后再调用feof(),才会得到文件结束的信息。
因此,如果运行如下程序:while(!feof(fp)){c = fgetc(fp);printf("%X/n", c);&}会发现多输出了一个FF,原因就是在读完最后一个字符后,fp-&flag仍然没有被置为_IOEOF,因而feof()仍然没有探测到文件结尾。直到再次调用fgetc()执行读操作,feof()才能探测到文件结尾。这样就多输出了一个-1(即FF)。
正确的写法应该是:c = fgetc(fp);while(!feof(fp)){printf("%X/n", c);&c = fgetc(fp);}&
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:43919次
排名:千里之外
原创:24篇
转载:14篇
评论:13条
(1)(1)(4)(2)(1)(5)(6)(13)(5)您还未登陆,请登录后操作!
关于介词of的用法
a packet of cigarette
students of chass five
五班的学生
我现在就是分不清楚,哪个名词放前,哪个名词放在of的后面。
a piece of bread
您的举报已经提交成功,我们将尽快处理,谢谢!
大家还关注}

我要回帖

更多关于 be of 的用法 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信