
Originally Posted by
Dante404
When I use the function printf() with a and b they seem to print the same number, but I don't understand why. To me, they seem to do the same thing as the int data type, but I think I'm missing something.
These kinds of claims are usually best made with some code to demonstrate what you tried and the output you received. For example, I compiled and ran:
Code:
#include <stdio.h>
int main(void)
{
const ssize_t a = -1;
const size_t b = (size_t) a;
printf("ssize_t: %ld\nsize_t: %zu\n", a, b);
return 0;
}
The output was:
Code:
ssize_t: -1
size_t: 18446744073709551615
which of course contradicts your claim that "they seem to print the same number".

Originally Posted by
Dante404
Moreover, how does (size_t) affect the value of a in "size_t b = (size_t) a"?
It performs a cast, which is not absolutely necessary since there is an implicit conversion from signed integer types to unsigned integer types, but is still good to highlight that such a conversion is happening.