C Programming Tutorial 31, Sizeof

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

On different systems variables can be different byte lengths. In 64 bit applications, pointers are 8 bytes instead of 4. I bet that an int is still 4 bytes, so I think the extra 4 in the structure, to add up to 16, comes from padding to make it "pretty" in memory.

iTzAdamX
Автор

Just an FYI, sizeof isn't a function, but it is actually a operator. You can test this a couple of ways, the easiest being sizeof without parentheses

TriplellOnLeague
Автор

Yes they are. I'm using 12.04LTS (64-bit) and sizeof(char*) returns 8 for me as well. If you think about it though they would have to. If sizeof(int) returns 8 bytes on a 64-bit OS, that means you can have 2^64 unique values--so for an unsigned integer, you can have 0 -> (2^64) - 1. So if a pointer had to be able to hold each of those addresses, then it must be 8 bytes in order to hold the address (2^64)-1, for example. So having 64-bit ints would be useless if pointers were only 4 bytes long.

tcbetka
Автор

you put more than one value in the memory block in your grid illustration. If each block in the grid represents a byte and a byte is 8 bits and each character, whether number, letter, or symbol is at least a byte, then how can you put more than one value in the block? Your tutorials have been clear to me up to this point.

LivingThoughts
Автор

Thanks for your quick responce i really enjoy your videos greetings grom the netherlands

ainogarddraco
Автор

I'm pretty sure that on 64 bit architectures the pointers are 8 bytes, so you're not doing anything wrong.

iTzAdamX
Автор

Very nice tutorial! Hope you make even more

Anothergames
Автор

hi Adam,

I get the number 16 out of it ( Running macbook air using GCC compiler with Gedit or Xcode texteditor


ainogarddraco
Автор

I'm using Ubuntu 12.04 and sizeof(char*) returns 8, is that just the way the architecture of my computer is? Or am I doing something wrong?

parthmehrotra
Автор

WATCH IN FULL SCREEN LOOKS LIKE SOMEONE IS TYPING ON YOUR COMPUTER :3

SmileCross
Автор

#include<stdio.h>
struct Node{
int data;
char *var;
}ch;
int main()
{
printf("%d", sizeof(ch));
return 0;


}
gives 16 on my pc, but as per the video it should be 4+4=8(?)
so, is this sizeof operator a machine dependent?

TheManumanohar
Автор

is someone here to answer question? if there is thn--
#include <stdio.h>

typedef struct
{
char name;
 int phone;

} client;
int main()
{
   printf("%d\n", sizeof(client));
   getch();
    return 0;

}
why does the size of my struct comes 8bytes, instead of 5? since there is one int and one char.

alam
Автор

Ok cool, guess I need to break out of the java mentality lol

parthmehrotra
visit shbcf.ru