By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,105 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,105 IT Pros & Developers. It's quick & easy.

Sizeof and increment operators

P: n/a
#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}
The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

Thanks,
Anjali.
Nov 14 '05 #1
Share this Question
Share on Google+
31 Replies


P: n/a
g_********@rediffmail.com (Anjali M) wrote:
printf("Sizeof of number is: %d\n", sizeof(number++)); The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?


From the last public draft of the C99 Standard, 6.5.3.4#2:

# The sizeof operator... If the type of the operand is a variable length
# array tye, the operand is evaluated; otherwise, the operand is not
# evaluated and the result is an integer constant.

Richard
Nov 14 '05 #2

P: n/a
Hi,

The sizeof operator just returns the size of the type or expressions,

so i guess,it is not defined to allow airthmetic operations within it.

Bye,

Smitha

"Anjali M" <g_********@rediffmail.com> wrote in message
news:99**************************@posting.google.c om...
#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}
The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

Thanks,
Anjali.

Nov 14 '05 #3

P: n/a
HI anjali,

Sizeof is an *operator* in C.
The operand expected in sizeof is either an identifier that is a
unary-expression, or a type-cast expression (that is, a type specifier
enclosed in parentheses). The unary-expression cannot represent a
bit-field object, an incomplete type, or a function designator.

A unary expression is an expression whose valuation is computed by
applying its (unary) operator to the valuation of its operand. There are
three kinds of unary operators:
(1) the logical complement unary operator "!",
(2) the plus unary operator "+", and
(3) the minus unary operator "-".

Hope this helps

sumukh
Anjali M wrote:
#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}
The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

Thanks,
Anjali.

Nov 14 '05 #4

P: n/a
g_********@rediffmail.com (Anjali M) wrote in message news:<99**************************@posting.google. com>...
#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}
The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

Thanks,
Anjali.


Hi Anjali,

The problem is not that of the ++ operator...but the 'sizeof'
operator.
The C Standard states that the operand of sizeof can be either a type
name or an expression.

e.g. sizeof (int) OR sizeof (a+b)

If it is an expression,then it will not be evaluated; See section
A.7.4.8 of K&R2 - [The C Programming Language 2/ed - Kernighan &
Ritchie ], Appendix A.

For the sake of convenience I'm reproducing the contents verbatim
here :

A.7.4.8 Sizeof Operator
The sizeof operator yields the number of bytes required to store an
object of the type of its operand. The operand is either an
expression,***_which is not evaluated_**, or a parenthesized type
name. When sizeof is applied to a char, the result is 1; when applied
to an array, the result is the total number of bytes in the array.
When applied to a structure or union, the result is the number of
bytes in the object, including any padding required to make the object
tile an array: the size of an array of n elements is n times the size
of one element. The operator may not be applied to an operand of
function type, or of incomplete type, or to a bit-field. The result is
an unsigned integral constant; the particular type is
implementation-defined.

Hence your expresion number++ never gets evaluated.So the value of
number doesn't increase.

HTH
Nitin
Nov 14 '05 #5

P: n/a
"smitha" <sm*****@cisco.com> wrote in message news:<1089097007.531247@sj-nntpcache-3>...
Hi,

The sizeof operator just returns the size of the type or expressions,

so i guess,it is not defined to allow airthmetic operations within it.
Wrong, the operand of sizeof operator is either type-names OR
expressions - which also includes arithmetic expressions.If it were
not defined for arithmetic expressions then the compiler must have
complained !!

You can even include a function call in the argument to sizeof !!!
Bye,

Smitha

"Anjali M" <g_********@rediffmail.com> wrote in message
news:99**************************@posting.google.c om...
#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}
The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

Thanks,
Anjali.

Nov 14 '05 #6

P: n/a
yes... sizeof is an operator and not a function. In a function call each
argument will be evaluated but this is not the case in sizeof.

"Nitin Bhardwaj" <ni*************@hotmail.com> wrote in message
news:17**************************@posting.google.c om...
"smitha" <sm*****@cisco.com> wrote in message

news:<1089097007.531247@sj-nntpcache-3>...
Hi,

The sizeof operator just returns the size of the type or expressions,

so i guess,it is not defined to allow airthmetic operations within it.


Wrong, the operand of sizeof operator is either type-names OR
expressions - which also includes arithmetic expressions.If it were
not defined for arithmetic expressions then the compiler must have
complained !!

You can even include a function call in the argument to sizeof !!!

Bye,

Smitha

"Anjali M" <g_********@rediffmail.com> wrote in message
news:99**************************@posting.google.c om...
#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}
The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

Thanks,
Anjali.

Nov 14 '05 #7

P: n/a
In <1089097007.531247@sj-nntpcache-3> "smitha" <sm*****@cisco.com> writes:
The sizeof operator just returns the size of the type or expressions,
Without evaluating them (except for VLAs in C99).
so i guess,it is not defined to allow airthmetic operations within it.


It is perfectly defined and allowed, they just won't be performed: the
compiler will merely figure out the type of the result.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #8

P: n/a
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???

--
+-------------------------------
| Charles and Francis Richmond
| richmond at plano dot net
| Re-Defeat Bush!!!
+-------------------------------
Nov 14 '05 #9

P: n/a
Charles Richmond <ri******@plano.net> wrote:
What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


Got fired, didya?

Richard
Nov 14 '05 #10

P: n/a
Charles Richmond <ri******@plano.net> scribbled the following:
Anjali M wrote:
#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


You are incredibly rude. What makes you so sure the OP sucked a job from
the US? What makes you so sure the OP has a job as a programmer at all?
This might just as well be a question from a genuine C newbie. And
besides, even if he did suck up the job from the US, what business is
that of yours? This is a technical newsgroup. If you need to vent your
patriotism, go to a politics newsgroup.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You could take his life and..."
- Mirja Tolsa
Nov 14 '05 #11

P: n/a
>Charles Richmond <ri******@plano.net> wrote in message >news:<40***************@plano.net>...

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???

It seems frm yr language that u hate Indians !!

Did u lost ur job to an Indian, buddy?

Cough up yr technical skills to match-up to ours & take on the
competition instead of making political transgressions on a technical
group like c.l.c!!
Nov 14 '05 #12

P: n/a
ni*************@hotmail.com (Nitin Bhardwaj) wrote:
Charles Richmond <ri******@plano.net> wrote in message >news:<40***************@plano.net>...
suck it up from the U. S.???


It seems frm yr language that u hate Indians !!

Did u lost ur job to an Indian, buddy?

Cough up yr technical skills to match-up to ours & take on the
competition instead of making political transgressions on a technical
group like c.l.c!!


Ow! I know the English did some pretty awful things in India, but do you
_have_ to take revenge by murdering their language? Leave that to the
USAnians, like Mr. Richmond ;->

Richard
Nov 14 '05 #13

P: n/a
In <40***************@plano.net> Charles Richmond <ri******@plano.net> writes:
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


How many job assignments like this have you seen? This is not only
a newbie question, it is a perfectly legitimate newbie question.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #14

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #15

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #16

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #17

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #18

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #19

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #20

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #21

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #22

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #23

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #24

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #25

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #26

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #27

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #28

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #29

P: n/a
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}

The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.
Nov 14 '05 #30

P: n/a
Anjali M <g_********@rediffmail.com> scribbled the following:
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???
I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_. So, better be careful before you
say something like this again.


It appears that Charles is an overly patriotic arrogant idiot. He is
probably so bitter about losing his own job to a foreign outsource
company that he thinks all Asians steal jobs from the US. The fact that
your problem was way too simple to have come up in a real job only
strenghtens your and my arguments and weakens Charles's. Are you still
in school? Are you teaching yourself C? It appears that the answer to
at least one of these questions is yes. If so, then Charles's
accusation isn't worth a toss, since you couldn't have stolen a job
from the US in that case.

PS. Was it really necessary to post an identical reply 16 times?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"As we all know, the hardware for the PC is great, but the software sucks."
- Petro Tyschtschenko
Nov 14 '05 #31

P: n/a
g_********@rediffmail.com (Anjali M) wrote:
Charles Richmond <ri******@plano.net> wrote in message news:<40***************@plano.net>...
What's the matter??? Can't you *do* the job after you
suck it up from the U. S.???


I don't know what you have got against me. I asked a very valid
question on this newsgroup and I _dont_ have to take this crap from
you. If you can be rude, so can _I_.


Sixteen times... what gave?

Richard
Nov 14 '05 #32

This discussion thread is closed

Replies have been disabled for this discussion.