size_t

This is a discussion on size_t within the C Programming forums, part of the General Programming Boards category; just wondering what is the point of this function "size_t" does the program below do the same thing as size_t? ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    141

    size_t

    just wondering what is the point of this function "size_t"

    does the program below do the same thing as size_t?


    Code:
    	int x;
    	x=sizeof(char);
    	printf("%d",x);
    Code:
    size_t x=sizeof(char);
    printf("%d",x)
    ------------------------

    also, what does this syntax mean?

    total=total<4 ? 4U:total;
    Last edited by bos1234; 03-04-2011 at 04:25 AM.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    size_t is not a function, it's a typedef of an unsigned integer datatype.

    sizeof is a compile-time operator that gives you the size of the datatype passed.

    The ?: construct is called the ternary operator. It's equivalent to

    Code:
    if (total < 4)
    {
        total = 4U;
    }
    else
    {
        total = total;
    }

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21