No We cannot use that information.. Reason
1 That is implantation of the compiler dependent and moreover is NOT
expose.
2 When we use malloc to allocate memory in heap. its the base address of
the value we get.. and incase of array there is no way you are restricted
to put your values beyond your
it will always work if array is statically allocated
Not if dynamically allocated, say using malloc etc.
On 30-Jan-13 1:55 PM, Prem Krishna Chettri wrote:
@Piyush .. Never works..
@All there is no way to do the given requirement in pure C.
On Wed, Jan 30, 2013 at 1:45 PM, Piyush
When malloc allocates memory it assigns a size field in the header to
indicate the size of the memory it allocates at a stretch. Can we not use
this information effectively?
On Jan 31, 2013 11:44 PM, Piyush piyush.to...@gmail.com wrote:
it will always work if array is statically allocated
Not
sizeof(array)/sizeof(array[0])
On 28-Jan-13 3:44 PM, Anil Sharma wrote:
How to calculate the size/lenght of an int array which is
passed as an ONLY argument to a function???
--
You received this message because you are subscribed to the Google
Groups Algorithm Geeks
@Piyush .. Never works..
@All there is no way to do the given requirement in pure C.
On Wed, Jan 30, 2013 at 1:45 PM, Piyush piyush.to...@gmail.com wrote:
sizeof(array)/sizeof(array[0])
On 28-Jan-13 3:44 PM, Anil Sharma wrote:
How to calculate the size/lenght of an int array which is
i already said this is not possible , in my intial draft , as we dont have
any information of memory owner in called function , just have base address
which is address of single element of the array .
On Wed, Jan 30, 2013 at 1:55 PM, Prem Krishna Chettri hprem...@gmail.comwrote:
@Piyush ..
How to calculate the size/lenght of an int array which is passed as an ONLY
argument to a function???
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
i think this is not possible as you are passing only base address of the
int array to it , there is not information about the owner .
On Mon, Jan 28, 2013 at 3:44 PM, Anil Sharma anilsharmau...@gmail.comwrote:
How to calculate the size/lenght of an int array which is passed as an
ONLY argument
If the array was declared as int array[100];
then sizeof operator will give you the size of that array. then length can
found as
length = sizeof(array)/sizeof(int);
if the array was declared dynamic then you can not find the length of that
array.
Naveen
On Mon, Jan 28, 2013 at 3:44 PM, Anil
why sizeof(vod) is giving ans 1 not error?
--
*UTKARSH SRIVASTAV
CSE-3
B-Tech 3rd Year
@MNNIT ALLAHABAD*
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from
bcoz void is a datatype, though u cant create obj of void type, then also it
hs to hs a size, so it hs been given the minimal sz i.e 1
On Tue, Sep 6, 2011 at 5:11 PM, UTKARSH SRIVASTAV
usrivastav...@gmail.comwrote:
why sizeof(vod) is giving ans 1 not error?
--
*UTKARSH SRIVASTAV
CSE-3
@all :
In any case , it sets the padding bytes according to the alignment of
largest sized element in structure
on dev c++ double aligns on 8 bytes boundary .. (so output 24 bytes)
whereas double aligns on 4 bytes boundary using gcc on linux... (so output
16 bytes)
these are for 32 bit
struct demo
{
char c;
double d;
int s;
};
what wud be the size of struct demo object?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe
its 16 bytes
for 32 bit computer ie 4 bytes
char occupies 1 byte and remaining 3 bytes are holes
double occupies 8 bytes
and int 4 bytes
since double starts on a new word boundary 3 bytes are holes
so its 16
On Sat, Aug 6, 2011 at 6:33 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:
struct
yep its 24 bytes it'll consider the double which is of maximum size here n
allocate the block a/c to that.
On Sat, Aug 6, 2011 at 6:55 PM, UTKARSH SRIVASTAV
usrivastav...@gmail.comwrote:
no the answer is 24 bytes ..read cell padding
--
*UTKARSH SRIVASTAV
CSE-3
B-Tech
yeah answer is 24 .. i knw..
i hav missed something in question that allocation starts at address which
is multiple of 4.
so i wanna ask.. why there is padding of 7 bytes after first char.. will nt
it work after 3 bytes padding
On Sat, Aug 6, 2011 at 6:55 PM, UTKARSH SRIVASTAV
Starting byte is always multiple of size. As double is of 8 bytes, so it
will start from 0,8,16 ... th byte..
On 6 August 2011 19:02, SANDEEP CHUGH sandeep.aa...@gmail.com wrote:
yeah answer is 24 .. i knw..
i hav missed something in question that allocation starts at address which
is
Hmmm i got the size as 16 bytes. I used gcc compiler ! wat may be the
reason?
On Sat, Aug 6, 2011 at 8:58 PM, payel roy smithpa...@gmail.com wrote:
Starting byte is always multiple of size. As double is of 8 bytes, so it
will start from 0,8,16 ... th byte..
On 6 August 2011 19:02, SANDEEP
Why does Ideone https://ideone.com/1Uwxx gives 16?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/L-zANxDDTUQJ.
To post to this group, send email to
even in http://www.codepad.org i got 16 bytes !!
On Sat, Aug 6, 2011 at 9:06 PM, Nitish Garg nitishgarg1...@gmail.comwrote:
Why does Ideone https://ideone.com/1Uwxx gives 16?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this
@payel : according to u,,starting address cannot be 4.. ok.
but wat if i hav used the following structure before that structure
struct demo1
{
char a;
int b;
char c;
}
On Sat, Aug 6, 2011 at 9:06 PM, Nitish Garg nitishgarg1...@gmail.comwrote:
Why does Ideone https://ideone.com/1Uwxx gives
@ sukran , nitish :
guys, i dnt knw about the output from these online compliers..
On Sat, Aug 6, 2011 at 9:20 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:
@payel : according to u,,starting address cannot be 4.. ok.
but wat if i hav used the following structure before that structure
the answer i got was 12 . let me know the answer u got in ur compiler!
On Sat, Aug 6, 2011 at 9:20 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:
@payel : according to u,,starting address cannot be 4.. ok.
but wat if i hav used the following structure before that structure
struct demo1
{
i guess it depends on ur system configuration...for 32 bit
machines...respective sizes allocated would be 4,4,8 :giving 16
on 64 bit machines it wud be 8,8,8: giving 24. Correct me if i am wrong.
On Sat, Aug 6, 2011 at 9:24 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:
@ sukran , nitish :
i got 24 when i compiled using dev c++ compiler
and i got 11 when compiled using turbo c compiler
On Sat, Aug 6, 2011 at 9:26 PM, sukran dhawan sukrandha...@gmail.comwrote:
the answer i got was 12 . let me know the answer u got in ur compiler!
On Sat, Aug 6, 2011 at 9:20 PM, SANDEEP CHUGH
it all depends on word size of the computer.since int by default is equal to
word size and double usually occupies 8 bytes all of these start from a new
memory boundary.so if only part of it filled rest of them will be holes.tat
is the whole reason why structures cannot be compared for equality
padding should depend on m/c size according to my logic
On Sat, Aug 6, 2011 at 9:32 PM, sukran dhawan sukrandha...@gmail.comwrote:
it all depends on word size of the computer.since int by default is equal
to word size and double usually occupies 8 bytes all of these start from a
new
On 6 August 2011 21:50, saurabh singh saurab...@gmail.com wrote:
padding should depend on m/c size according to my logic
machine as well as the compiler
On Sat, Aug 6, 2011 at 9:32 PM, sukran dhawan sukrandha...@gmail.comwrote:
it all depends on word size of the computer.since int
I am also getting 24 bytes but y it is taking it every data type as 8,8,8 as
if we take it alone it is 1 for char and 4 for int and 8 for doble as it is
giving 24 which means it is setting every data type as 8 bytes.
On Sat, Aug 6, 2011 at 9:28 PM, Aditya Virmani virmanisadi...@gmail.comwrote:
On 6 August 2011 23:27, Nitin coolguyinat...@gmail.com wrote:
I am also getting 24 bytes but y it is taking it every data type as 8,8,8
as if we take it alone it is 1 for char and 4 for int and 8 for doble as it
is giving 24 which means it is setting every data type as 8 bytes.
it should be
on gcc it is 16 bytes and on dev cpp its 24 bytes
On Sat, Aug 6, 2011 at 11:10 AM, siddharth srivastava
akssps...@gmail.comwrote:
On 6 August 2011 23:27, Nitin coolguyinat...@gmail.com wrote:
I am also getting 24 bytes but y it is taking it every data type as 8,8,8
as if we take it
#includestdio.h
#includestddef.h
struct node{
int a;
char *b[5];
struct node *link;
};
main()
{
int a;
a=sizeof(struct node);
printf(%d,a);
getchar();
return 0;
}
Whats the output..?
--
You received this message because you are
28.?
int a- 4
Five array of pointer to char 20( each pointer of 4 bytes)
struct node * 4 bytes.
On Tue, Jul 26, 2011 at 6:10 PM, Puneet Gautam puneet.nsi...@gmail.comwrote:
#includestdio.h
#includestddef.h
struct node{
int a;
char *b[5];
struct node *link;
};
4+20+4 = 28 bytes it should be i think
On Tue, Jul 26, 2011 at 6:10 PM, Puneet Gautam puneet.nsi...@gmail.comwrote:
#includestdio.h
#includestddef.h
struct node{
int a;
char *b[5];
struct node *link;
};
main()
{
int a;
a=sizeof(struct node);
why isn't padding done here? We have seen previous posts on size of
structures, where due to padding, the size was not just the sum of size of
datatypes, but also padded bytes.
like here, int (4 bytes), then why is 3 bytes not padded after this, before
char* arr[5] (20 bytes)?
On Tue, Jul 26,
@akshata: here padding wont come into picture coz int a =4byte, char
*b[5]=4*5byte, *link=4byte all are multiple of 4 . ans will be 28 byte
On Tue, Jul 26, 2011 at 6:42 PM, Akshata Sharma
akshatasharm...@gmail.comwrote:
why isn't padding done here? We have seen previous posts on size of
36 matches
Mail list logo