Re: [algogeeks] size of array

2013-02-03 Thread Prem Krishna Chettri
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

Re: [algogeeks] size of array

2013-01-31 Thread Piyush
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

Re: [algogeeks] size of array

2013-01-31 Thread Abhirup Ghosh
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

Re: [algogeeks] size of array

2013-01-30 Thread Piyush
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

Re: [algogeeks] size of array

2013-01-30 Thread Prem Krishna Chettri
@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

Re: [algogeeks] size of array

2013-01-30 Thread Nishant Pandey
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 ..

[algogeeks] size of array

2013-01-29 Thread Anil Sharma
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

Re: [algogeeks] size of array

2013-01-29 Thread Nishant Pandey
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

Re: [algogeeks] size of array

2013-01-29 Thread naveen bansal
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

[algogeeks] size of

2011-09-06 Thread UTKARSH SRIVASTAV
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

Re: [algogeeks] size of

2011-09-06 Thread rahul vatsa
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

Re: [algogeeks] size -------

2011-08-07 Thread SANDEEP CHUGH
@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

[algogeeks] size -------

2011-08-06 Thread SANDEEP CHUGH
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

Re: [algogeeks] size -------

2011-08-06 Thread sukran dhawan
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

Re: [algogeeks] size -------

2011-08-06 Thread Gyanendra Kumar
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

Re: [algogeeks] size -------

2011-08-06 Thread SANDEEP CHUGH
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

Re: [algogeeks] size -------

2011-08-06 Thread payel roy
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

Re: [algogeeks] size -------

2011-08-06 Thread sukran dhawan
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

Re: [algogeeks] size -------

2011-08-06 Thread Nitish Garg
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

Re: [algogeeks] size -------

2011-08-06 Thread sukran dhawan
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

Re: [algogeeks] size -------

2011-08-06 Thread SANDEEP CHUGH
@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

Re: [algogeeks] size -------

2011-08-06 Thread SANDEEP CHUGH
@ 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

Re: [algogeeks] size -------

2011-08-06 Thread sukran dhawan
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 {

Re: [algogeeks] size -------

2011-08-06 Thread Aditya Virmani
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 :

Re: [algogeeks] size -------

2011-08-06 Thread SANDEEP CHUGH
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

Re: [algogeeks] size -------

2011-08-06 Thread sukran dhawan
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

Re: [algogeeks] size -------

2011-08-06 Thread saurabh singh
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

Re: [algogeeks] size -------

2011-08-06 Thread siddharth srivastava
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

Re: [algogeeks] size -------

2011-08-06 Thread Nitin
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:

Re: [algogeeks] size -------

2011-08-06 Thread siddharth srivastava
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

Re: [algogeeks] size -------

2011-08-06 Thread coder dumca
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

[algogeeks] size of self referential structure

2011-07-26 Thread Puneet Gautam
#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

Re: [algogeeks] size of self referential structure

2011-07-26 Thread Neeraj Gupta
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; };

Re: [algogeeks] size of self referential structure

2011-07-26 Thread sunny agrawal
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);

Re: [algogeeks] size of self referential structure

2011-07-26 Thread Akshata Sharma
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,

Re: [algogeeks] size of self referential structure

2011-07-26 Thread aditya kumar
@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