Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What is size_t in C?

I'm getting mistaken for size_t in C. I realize that it is returned by the sizeof operator. However, what precisely right? Is it a data type?

Suppose I have a for loop:
for(i = 0; i < some_size; i++)

Should I use int i; or size_t i;?
by

2 Answers

bape
int* and *size_t* are long unsigned integer datatypes in C language. But the difference is *size_t* takes 8 bytes and *int takes 4 bytes of memory in 32 bit GCC compiler. We see this with an example:

#include <stdio.h>
int main(){
printf("int size is %ld\n", sizeof(int));
printf("int size is %ld\n", sizeof(size_t));
return 0;
}
RoliMishra
size_t is a type that can hold any array index.

Depending on the implementation, it can be any of:

unsigned char

unsigned short

unsigned int

unsigned long

unsigned long long

Here's how size_t is defined in stddef.h of my machine:

typedef unsigned long size_t;

Login / Signup to Answer the Question.