Because it is a compile-time operator that, in order to calculate the size of an object, requires type information that is only available at compile-time. This doesn't hold for C++.

i have read this statement roght now when implementing one library function. why it doesn't hold for C++?

secondly, i am finding it get one thing : "avavilable at compile-time only" ? can anyone explain it to me ? thanks.

Recommended Answers

All 22 Replies

why it doesn't hold for C++?

I'd suspect that the person who wrote that was thinking of C++'s RTTI (runtime type information) features. That really has nothing to do with the sizeof operator though.

and deceptikon what about my second question ? Can you please throw some light on that also ?

I don't understand the "question". Please elaborate.

@deceptikon i am finding it hard to get one thing in the sentence : "availiable at compile-time only" ? I mean this when i said "question" in the above post. thanks

Type information is lost after compilation, that's why C decompilers suck ass. We've discussed this.

yes, i remember it very very well that we have discussed this. In next semester , i am going to study about compilers which i hope will make compilers things better.

okay! One more question i wana ask you here only, if anyone asks me why sizeof is an operator not a function, then what exactly (very specific) i should say him/her ? Can you give any statement or hint so that i can get from it. thanks.

if anyone asks me why sizeof is an operator not a function, then what exactly (very specific) i should say him/her

I'd ask a socratic counter question: how would a function (an inherently runtime entity) execute at compile time?

yes! it is true ! but is it the reason ? i mean it is not a well defined answer if a high-grade person(interviewer/teacher/professor) asks and i counter question him/her like this. i know that it is a function and it can't be executed at the compile time.

commented: good question :) +4

i mean it is not a well defined answer if a high-grade person(interviewer/teacher/professor) asks and i counter question him/her like this.

I'd accept that answer as an interviewer. It clearly and eloquently (in my opinion) shows that you understand the issues involved.

:-o really ? Have you ever gone as a interviwer to any university or college ?

Have you ever gone as a interviwer to any university or college ?

No, but I regularly interview candidate programmers looking for a job in the real world.

ohh! wow! Acting as an intrviewer from any company ? it's a great job! initially, before my first interview, i afraid from them like they will eat me if i say something wrong ;)

Acting as an intrviewer from any company ? it's a great job!

It's not really that big of a deal.

i afraid from them like they will eat me if i say something wrong ;)

While some nervousness is understandable and overly confident people raise red flags in an interview, being afraid of the interviewer is a bad thing. In my first programming interview (as the candidate) I wouldn't back down when the interviewer thought my answer to a question had a bug and I knew it didn't. I got that job over other, probably better, candidates because I was willing to fight when it mattered. Backing down and changing code to fix an imaginary bug very often introduces real bugs, and that can end up being a very costly mistake.

oh.. great tip! who knows may be this thing only make me to get pass in the interview. but what to do in a situation when we don't know the answer fully correctly. then should we say it or not ? like it is better to shut off when u dont know the answer fully correctly or say what ever u know may be it is wrong?

but what to do in a situation when we don't know the answer fully correctly.

Say what you know and admit that you're not sure. You'd be shocked at how few people seem capable of saying "I don't know". In fact, it's so ridicuous that merely admitting you don't know the answer and suggesting ways to find it can land you a job all by itself.

commented: nice +4

It's surprising how much information an interviewer can obtain even from an incorrect answer.

@deceptikon, Bob
Now that we are discussing about questions in interviews, i am curious to know what kind of questions do you generally see people asking? As far as i have seen/heard many interviewers tend to ask things that you would find in any book. I mean something related to syntax of a language, etc.

perhaps creating a new thread for this is appropriate?

Thanks!

perhaps creating a new thread for this is appropriate?

I think that would be best.

@deceptikon first tell me where should the thread need to be placed as i dont want more infraction points. :( secondly, please be active over that thread as I was seriously thinking that there will be someone who will come and say this thing which myk45 has said. :(

Geeks' Lounge and Community Center would probably be the best place, though if it's directed at C interviews the the C forum is also appropriate. And I don't care who starts the thread (you or myk45), just coordinate so that you don't both make one. ;)

commented: really thanks ;) +2

@myke45 are you making it or i should ? tell me here only, and if you making it , then where are you making ? and if i need to make, then where should i make ? thanks :-)

someone who will come and say this thing which myk45 has said

I didn't mean to interrupt the thread. I just felt having a new thread with an appropriate title would benifit the lot. I have created a new thread

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.