Difference(When Being Applied to My Code) Between Int(10) and Int(12)

What is the difference (when being applied to my code) between INT(10) and INT(12)?

Short answer: there's no difference.

The display width is passed back in the "meta data". It's up to the application to make use of it. Normally it's just ignored. I don't think you can get it using the mysql functions, but you might be able to with mysqli using mysqli_fetch_field_direct.

mysql constraint int(10) referencing int(11)

It's no problem. The INT(10) and INT(11) are exactly the same data type (32-bit signed integer) with respect to storage and range of values. The integer argument is only a hint for display.

Also varchar columns of different lengths are okay to use in foreign key relationships. Obviously these do have a different range of values they permit. But it's okay.

Say for example the parent table has a shorter VARCHAR(10) and the child has VARCHAR(20). The child still can't use a string longer than 10 characters, because it must match a string in the parent table, and there simply won't be any longer than 10 characters.

It works in reverse too; if the parent has VARCHAR(20) and the child has VARCHAR(10). The child won't be able to reference longer strings in the parent, but it's never mandatory that the child table reference every value in the parent table, only those it can reference.

Based on this reasoning, you might think that the same logic would apply to integers, so a SMALLINT should be able to reference a BIGINT. But MySQL doesn't permit this.

Whats the difference between int *p=10 and int *p = (int *)10?

Both cases convert the integer 10 to a pointer type which is used to initialize an int *. The cast in the second case makes it explicit that this behavior is intentional.

While converting from an integer to pointer is allowed, the assignment operator (and by extension, initialization) does not specifically allow this conversion, so a cast it required to be conforming. Many compilers however will still allow this and simply issue a warning (as your apparently does).

Note however that actually attempting to use a pointer that is assigned a specific numeric value will most likely cause a crash unless you're on a embedded system that supports reading or writing specific memory addresses.

What is the maximum size of int(10) in Mysql

INT(10) means you probably defined it as INT UNSIGNED.

So, you can store numbers from 0 up to 4294967295 (note that the maximum value has 10 digits, so MySQL automatically added the (10) in the column definition which (10) is just a format hint and nothing more. It has no effect on how big number you can store).

You can use BIGINT UNSIGNED if you want to store bigger values. See the MySQL docs: Integer Types (Exact Value)

int(11) vs. int(anything else)

The x in INT(x) has nothing to do with space requirements or any other performance issues, it's really just the display width. Generally setting the display widths to a reasonable value is mostly useful with the UNSIGNED ZEROFILL option.

//INT(4) UNSIGNED ZEROFILL
0001
0002
...
0099
...
0999
...
9999
...
10000

//INT(2) UNSIGNED ZEROFILL
01
02
...
09
...
99
...
100

Without the UNSIGNED ZEROFILL option the value will be left-padded with spaces to the appropriate display width.

//INT(4)
1
2
...
99
...
999
...
9999
...
10000

//INT(2)
1
2
...
9
...
99
...
100

Difference between *ptr[10] and (*ptr)[10]

int *ptr[10];

This is an array of 10 int* pointers, not as you would assume, a pointer to an array of 10 ints

int (*ptr)[10];

This is a pointer to an array of 10 int

It is I believe the same as int *ptr; in that both can point to an array, but the given form can ONLY point to an array of 10 ints

What is the difference between short int and int in C?

They may have the same size, but it is guaranteed that int is equal to or bigger than short int.



Related Topics



Leave a reply



Submit