Re: [algogeeks] Re: C Doubts

2011-07-18 Thread Nishant Mittal
@abhi
we can do it without passing the address to a function. just store the
address of const variable in another variable and change the value...

On Mon, Jul 18, 2011 at 11:56 AM, Abhi abhi123khat...@gmail.com wrote:

 Perhaps the only way to alter the value of a variable declared constant in
 C is through passing its address to a function and changing the value
 henceforth though it generates a warning of 'discarding the qualifiers'.

 --
 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/-/SbHlNcA7Fj8J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: C Doubts

2011-07-17 Thread aditya kumar
 struct st
{
char ch1;
long double ld;
}s;
printf(%d,sizeof(s));
//output : 24 (for 32-bit compiler)
-as i have mentioned above the behaviour is undefined in case of sizeof
(struct)
can any one explain me why the padding concept does not work here ??

On Mon, Jul 18, 2011 at 12:13 AM, Parthiban jega...@gmail.com wrote:

 @Abhi:
 Answers:
 1. whenever a 'const' qualifier is added previously to a variable
 declaration it means that the value of the variable is automatically
 initialized to '0'(because of the 'auto' type of the const variable)  and
 cannot be changed in any of the following assignment statements to the const
 variable.

 2.
 Here for the structure struct s1 since the entire structure is ending
 within 8 bytes no padding is done which means
 s1: [char a]
1byte
 but for the structure struct s2 consider the following:
 s2: [ char a
 1byte
-- int a---
--4bytes]
 so here the concept of padding comes to make all the variable aligned in
 even boundaries and so the structure after aligning will look as:
 s2: [ -- char b
 --4byte-
-- int a---
--4bytes]

 so the size of strcut s2 will be 8bytes..

  --
 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/-/FoHpgvrjnm0J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: C Doubts

2011-07-17 Thread sagar pareek
sizeof long double is 12. So padding concept is perfectly working

On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar aditya.kumar130...@gmail.com
 wrote:

 struct st
 {
 char ch1;
  long double ld;
 }s;
 printf(%d,sizeof(s));
 //output : 24 (for 32-bit compiler)
 -as i have mentioned above the behaviour is undefined in case of sizeof
 (struct)
 can any one explain me why the padding concept does not work here ??

 On Mon, Jul 18, 2011 at 12:13 AM, Parthiban jega...@gmail.com wrote:

 @Abhi:
 Answers:
 1. whenever a 'const' qualifier is added previously to a variable
 declaration it means that the value of the variable is automatically
 initialized to '0'(because of the 'auto' type of the const variable)  and
 cannot be changed in any of the following assignment statements to the const
 variable.

 2.
 Here for the structure struct s1 since the entire structure is ending
 within 8 bytes no padding is done which means
 s1: [char a]
1byte
 but for the structure struct s2 consider the following:
 s2: [ char a
 1byte
-- int a---
--4bytes]
 so here the concept of padding comes to make all the variable aligned in
 even boundaries and so the structure after aligning will look as:
 s2: [ -- char b
 --4byte-
-- int a---
--4bytes]

 so the size of strcut s2 will be 8bytes..

  --
 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/-/FoHpgvrjnm0J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
**Regards
SAGAR PAREEK
COMPUTER SCIENCE AND ENGINEERING
NIT 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 this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: C Doubts

2011-07-17 Thread aditya kumar
@prateek . can you explain me ?? i dint get padding logic in this example of
mine.

On Mon, Jul 18, 2011 at 12:30 AM, sagar pareek sagarpar...@gmail.comwrote:

 sizeof long double is 12. So padding concept is perfectly working


 On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 struct st
 {
  char ch1;
  long double ld;
 }s;
 printf(%d,sizeof(s));
 //output : 24 (for 32-bit compiler)
 -as i have mentioned above the behaviour is undefined in case of sizeof
 (struct)
 can any one explain me why the padding concept does not work here ??

 On Mon, Jul 18, 2011 at 12:13 AM, Parthiban jega...@gmail.com wrote:

 @Abhi:
 Answers:
 1. whenever a 'const' qualifier is added previously to a variable
 declaration it means that the value of the variable is automatically
 initialized to '0'(because of the 'auto' type of the const variable)  and
 cannot be changed in any of the following assignment statements to the const
 variable.

 2.
 Here for the structure struct s1 since the entire structure is ending
 within 8 bytes no padding is done which means
 s1: [char a]
1byte
 but for the structure struct s2 consider the following:
 s2: [ char a
 1byte
-- int a---
--4bytes]
 so here the concept of padding comes to make all the variable aligned in
 even boundaries and so the structure after aligning will look as:
 s2: [ -- char b
 --4byte-
-- int a---
--4bytes]

 so the size of strcut s2 will be 8bytes..

  --
 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/-/FoHpgvrjnm0J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: C Doubts

2011-07-17 Thread Nikhil Gupta
@Aditya

Here is the padding effect :

Address of char : starts anywhere
Address of long double : starts at 11 address locations from char variable
-- 1+11+12=24 bytes

On Mon, Jul 18, 2011 at 1:10 AM, sagar pareek sagarpar...@gmail.com wrote:

 @aditya
 actually first see your post, you have written o/p=24 accordingly padding
 done is perfect. But actually its printing 16.
 So now question arises of padding

 and its pareek not prateek :)


 On Mon, Jul 18, 2011 at 12:38 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @prateek . can you explain me ?? i dint get padding logic in this example
 of mine.

 On Mon, Jul 18, 2011 at 12:30 AM, sagar pareek sagarpar...@gmail.comwrote:

 sizeof long double is 12. So padding concept is perfectly working


  On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 struct st
 {
  char ch1;
  long double ld;
 }s;
 printf(%d,sizeof(s));
 //output : 24 (for 32-bit compiler)
 -as i have mentioned above the behaviour is undefined in case of sizeof
 (struct)
 can any one explain me why the padding concept does not work here ??

 On Mon, Jul 18, 2011 at 12:13 AM, Parthiban jega...@gmail.com wrote:

 @Abhi:
 Answers:
 1. whenever a 'const' qualifier is added previously to a variable
 declaration it means that the value of the variable is automatically
 initialized to '0'(because of the 'auto' type of the const variable)  and
 cannot be changed in any of the following assignment statements to the 
 const
 variable.

 2.
 Here for the structure struct s1 since the entire structure is ending
 within 8 bytes no padding is done which means
 s1: [char a]
1byte
 but for the structure struct s2 consider the following:
 s2: [ char a
 1byte
-- int a---
--4bytes]
 so here the concept of padding comes to make all the variable aligned
 in even boundaries and so the structure after aligning will look as:
 s2: [ -- char b
 --4byte-
-- int a---
--4bytes]

 so the size of strcut s2 will be 8bytes..

  --
 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/-/FoHpgvrjnm0J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Nikhil Gupta
Senior Co-ordinator, Publicity
CSI, NSIT Students' Branch
NSIT, New Delhi, India

-- 
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 this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: C Doubts

2011-07-17 Thread aditya kumar
@pareek..my compiler gives 24 . newazz if ansa is 16 acc to you then it
follows padding principle perfectly. since memory cycle invloves 1 word
hence char will take 1 byte nd 3 bytes will be padded up . rest 12 bytes
will come from long double so 4+12=16 bytes :)
n ya sry abt d name .

On Mon, Jul 18, 2011 at 1:10 AM, sagar pareek sagarpar...@gmail.com wrote:

 @aditya
 actually first see your post, you have written o/p=24 accordingly padding
 done is perfect. But actually its printing 16.
 So now question arises of padding

 and its pareek not prateek :)


 On Mon, Jul 18, 2011 at 12:38 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @prateek . can you explain me ?? i dint get padding logic in this example
 of mine.

 On Mon, Jul 18, 2011 at 12:30 AM, sagar pareek sagarpar...@gmail.comwrote:

 sizeof long double is 12. So padding concept is perfectly working


  On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 struct st
 {
  char ch1;
  long double ld;
 }s;
 printf(%d,sizeof(s));
 //output : 24 (for 32-bit compiler)
 -as i have mentioned above the behaviour is undefined in case of sizeof
 (struct)
 can any one explain me why the padding concept does not work here ??

 On Mon, Jul 18, 2011 at 12:13 AM, Parthiban jega...@gmail.com wrote:

 @Abhi:
 Answers:
 1. whenever a 'const' qualifier is added previously to a variable
 declaration it means that the value of the variable is automatically
 initialized to '0'(because of the 'auto' type of the const variable)  and
 cannot be changed in any of the following assignment statements to the 
 const
 variable.

 2.
 Here for the structure struct s1 since the entire structure is ending
 within 8 bytes no padding is done which means
 s1: [char a]
1byte
 but for the structure struct s2 consider the following:
 s2: [ char a
 1byte
-- int a---
--4bytes]
 so here the concept of padding comes to make all the variable aligned
 in even boundaries and so the structure after aligning will look as:
 s2: [ -- char b
 --4byte-
-- int a---
--4bytes]

 so the size of strcut s2 will be 8bytes..

  --
 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/-/FoHpgvrjnm0J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: C Doubts

2011-07-17 Thread Nikhil Gupta
@Sagar

Memory sizes of long double variables are compiler and system configuration
dependent. So obviously, in accordance with your compiler, the size of long
double is 8 bytes.

On Mon, Jul 18, 2011 at 1:22 AM, Nikhil Gupta nikhilgupta2...@gmail.comwrote:

 @Aditya

 Here is the padding effect :

 Address of char : starts anywhere
 Address of long double : starts at 11 address locations from char variable
 -- 1+11+12=24 bytes


 On Mon, Jul 18, 2011 at 1:10 AM, sagar pareek sagarpar...@gmail.comwrote:

 @aditya
 actually first see your post, you have written o/p=24 accordingly padding
 done is perfect. But actually its printing 16.
 So now question arises of padding

 and its pareek not prateek :)


 On Mon, Jul 18, 2011 at 12:38 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @prateek . can you explain me ?? i dint get padding logic in this example
 of mine.

 On Mon, Jul 18, 2011 at 12:30 AM, sagar pareek sagarpar...@gmail.comwrote:

 sizeof long double is 12. So padding concept is perfectly working


  On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 struct st
 {
  char ch1;
  long double ld;
 }s;
 printf(%d,sizeof(s));
 //output : 24 (for 32-bit compiler)
 -as i have mentioned above the behaviour is undefined in case of
 sizeof (struct)
 can any one explain me why the padding concept does not work here ??

 On Mon, Jul 18, 2011 at 12:13 AM, Parthiban jega...@gmail.com wrote:

 @Abhi:
 Answers:
 1. whenever a 'const' qualifier is added previously to a variable
 declaration it means that the value of the variable is automatically
 initialized to '0'(because of the 'auto' type of the const variable)  and
 cannot be changed in any of the following assignment statements to the 
 const
 variable.

 2.
 Here for the structure struct s1 since the entire structure is ending
 within 8 bytes no padding is done which means
 s1: [char a]
1byte
 but for the structure struct s2 consider the following:
 s2: [ char a
 1byte
-- int a---
--4bytes]
 so here the concept of padding comes to make all the variable aligned
 in even boundaries and so the structure after aligning will look as:
 s2: [ -- char b
 --4byte-
-- int a---
--4bytes]

 so the size of strcut s2 will be 8bytes..

  --
 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/-/FoHpgvrjnm0J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Nikhil Gupta
 Senior Co-ordinator, Publicity
 CSI, NSIT Students' Branch
 NSIT, New Delhi, India




-- 
Nikhil Gupta
Senior Co-ordinator, Publicity
CSI, NSIT Students' Branch
NSIT, New Delhi, India

-- 
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 this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: C Doubts

2011-07-17 Thread aditya kumar
@Nikhil
why is Address of long double : starts at 11 address locations from char
variable ??
is shud start from 3rd adress location from char variable bcoz memory cycle
involves a word so are you padding 11bytes ??

On Mon, Jul 18, 2011 at 1:24 AM, Nikhil Gupta nikhilgupta2...@gmail.comwrote:

 @Sagar

 Memory sizes of long double variables are compiler and system configuration
 dependent. So obviously, in accordance with your compiler, the size of long
 double is 8 bytes.


 On Mon, Jul 18, 2011 at 1:22 AM, Nikhil Gupta 
 nikhilgupta2...@gmail.comwrote:

 @Aditya

 Here is the padding effect :

 Address of char : starts anywhere
 Address of long double : starts at 11 address locations from char variable
 -- 1+11+12=24 bytes


 On Mon, Jul 18, 2011 at 1:10 AM, sagar pareek sagarpar...@gmail.comwrote:

 @aditya
 actually first see your post, you have written o/p=24 accordingly padding
 done is perfect. But actually its printing 16.
 So now question arises of padding

 and its pareek not prateek :)


 On Mon, Jul 18, 2011 at 12:38 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @prateek . can you explain me ?? i dint get padding logic in this
 example of mine.

 On Mon, Jul 18, 2011 at 12:30 AM, sagar pareek 
 sagarpar...@gmail.comwrote:

 sizeof long double is 12. So padding concept is perfectly working


  On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 struct st
 {
  char ch1;
  long double ld;
 }s;
 printf(%d,sizeof(s));
 //output : 24 (for 32-bit compiler)
 -as i have mentioned above the behaviour is undefined in case of
 sizeof (struct)
 can any one explain me why the padding concept does not work here ??

 On Mon, Jul 18, 2011 at 12:13 AM, Parthiban jega...@gmail.comwrote:

 @Abhi:
 Answers:
 1. whenever a 'const' qualifier is added previously to a variable
 declaration it means that the value of the variable is automatically
 initialized to '0'(because of the 'auto' type of the const variable)  
 and
 cannot be changed in any of the following assignment statements to the 
 const
 variable.

 2.
 Here for the structure struct s1 since the entire structure is ending
 within 8 bytes no padding is done which means
 s1: [char a]
1byte
 but for the structure struct s2 consider the following:
 s2: [ char a
 1byte
-- int a---
--4bytes]
 so here the concept of padding comes to make all the variable aligned
 in even boundaries and so the structure after aligning will look as:
 s2: [ -- char b
 --4byte-
-- int a---
--4bytes]

 so the size of strcut s2 will be 8bytes..

  --
 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/-/FoHpgvrjnm0J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Nikhil Gupta
 Senior Co-ordinator, Publicity
 CSI, NSIT Students' Branch
 NSIT, New Delhi, India




 --
 Nikhil Gupta
 Senior Co-ordinator, Publicity
 CSI, NSIT Students' Branch
 NSIT, New Delhi, India

  --
 You received this message because 

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread Nikhil Gupta
That is again compiler dependent. Usually when hardware configuration is
taken into account, the compiler uses padding of 3 bytes. But in some cases,
for the ease of hardware access and faster implementation, 11 bytes are
padded. Possibly depends on your system hardware's synchronization with the
compiler.

On Mon, Jul 18, 2011 at 1:27 AM, aditya kumar
aditya.kumar130...@gmail.comwrote:

 @Nikhil
 why is Address of long double : starts at 11 address locations from char
 variable ??
 is shud start from 3rd adress location from char variable bcoz memory cycle
 involves a word so are you padding 11bytes ??


 On Mon, Jul 18, 2011 at 1:24 AM, Nikhil Gupta 
 nikhilgupta2...@gmail.comwrote:

 @Sagar

 Memory sizes of long double variables are compiler and system
 configuration dependent. So obviously, in accordance with your compiler, the
 size of long double is 8 bytes.


 On Mon, Jul 18, 2011 at 1:22 AM, Nikhil Gupta 
 nikhilgupta2...@gmail.comwrote:

 @Aditya

 Here is the padding effect :

 Address of char : starts anywhere
 Address of long double : starts at 11 address locations from char
 variable -- 1+11+12=24 bytes


 On Mon, Jul 18, 2011 at 1:10 AM, sagar pareek sagarpar...@gmail.comwrote:

 @aditya
 actually first see your post, you have written o/p=24 accordingly
 padding done is perfect. But actually its printing 16.
 So now question arises of padding

 and its pareek not prateek :)


 On Mon, Jul 18, 2011 at 12:38 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @prateek . can you explain me ?? i dint get padding logic in this
 example of mine.

 On Mon, Jul 18, 2011 at 12:30 AM, sagar pareek 
 sagarpar...@gmail.comwrote:

 sizeof long double is 12. So padding concept is perfectly working


  On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 struct st
 {
  char ch1;
  long double ld;
 }s;
 printf(%d,sizeof(s));
 //output : 24 (for 32-bit compiler)
 -as i have mentioned above the behaviour is undefined in case of
 sizeof (struct)
 can any one explain me why the padding concept does not work here ??

 On Mon, Jul 18, 2011 at 12:13 AM, Parthiban jega...@gmail.comwrote:

 @Abhi:
 Answers:
 1. whenever a 'const' qualifier is added previously to a variable
 declaration it means that the value of the variable is automatically
 initialized to '0'(because of the 'auto' type of the const variable)  
 and
 cannot be changed in any of the following assignment statements to the 
 const
 variable.

 2.
 Here for the structure struct s1 since the entire structure is
 ending within 8 bytes no padding is done which means
 s1: [char a]
1byte
 but for the structure struct s2 consider the following:
 s2: [ char a
 1byte
-- int a---
--4bytes]
 so here the concept of padding comes to make all the variable
 aligned in even boundaries and so the structure after aligning will 
 look as:
 s2: [ -- char b
 --4byte-
-- int a---
--4bytes]

 so the size of strcut s2 will be 8bytes..

  --
 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/-/FoHpgvrjnm0J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this 

Re: [algogeeks] Re: C Doubts

2011-07-17 Thread sagar pareek
@nikhil my compiler gives sizeof long double =12
so aditya's concept is correct

On Mon, Jul 18, 2011 at 1:35 AM, aditya kumar
aditya.kumar130...@gmail.comwrote:

 @Nikhil
 thnks :)


 On Mon, Jul 18, 2011 at 1:32 AM, Nikhil Gupta 
 nikhilgupta2...@gmail.comwrote:

 That is again compiler dependent. Usually when hardware configuration is
 taken into account, the compiler uses padding of 3 bytes. But in some cases,
 for the ease of hardware access and faster implementation, 11 bytes are
 padded. Possibly depends on your system hardware's synchronization with the
 compiler.


 On Mon, Jul 18, 2011 at 1:27 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @Nikhil
 why is Address of long double : starts at 11 address locations from char
 variable ??
 is shud start from 3rd adress location from char variable bcoz memory
 cycle involves a word so are you padding 11bytes ??


 On Mon, Jul 18, 2011 at 1:24 AM, Nikhil Gupta nikhilgupta2...@gmail.com
  wrote:

 @Sagar

 Memory sizes of long double variables are compiler and system
 configuration dependent. So obviously, in accordance with your compiler, 
 the
 size of long double is 8 bytes.


 On Mon, Jul 18, 2011 at 1:22 AM, Nikhil Gupta 
 nikhilgupta2...@gmail.com wrote:

 @Aditya

 Here is the padding effect :

 Address of char : starts anywhere
 Address of long double : starts at 11 address locations from char
 variable -- 1+11+12=24 bytes


 On Mon, Jul 18, 2011 at 1:10 AM, sagar pareek 
 sagarpar...@gmail.comwrote:

 @aditya
 actually first see your post, you have written o/p=24 accordingly
 padding done is perfect. But actually its printing 16.
 So now question arises of padding

 and its pareek not prateek :)


 On Mon, Jul 18, 2011 at 12:38 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 @prateek . can you explain me ?? i dint get padding logic in this
 example of mine.

 On Mon, Jul 18, 2011 at 12:30 AM, sagar pareek 
 sagarpar...@gmail.com wrote:

 sizeof long double is 12. So padding concept is perfectly working


  On Mon, Jul 18, 2011 at 12:26 AM, aditya kumar 
 aditya.kumar130...@gmail.com wrote:

 struct st
 {
  char ch1;
  long double ld;
 }s;
 printf(%d,sizeof(s));
 //output : 24 (for 32-bit compiler)
 -as i have mentioned above the behaviour is undefined in case of
 sizeof (struct)
 can any one explain me why the padding concept does not work here
 ??

 On Mon, Jul 18, 2011 at 12:13 AM, Parthiban jega...@gmail.comwrote:

 @Abhi:
 Answers:
 1. whenever a 'const' qualifier is added previously to a variable
 declaration it means that the value of the variable is automatically
 initialized to '0'(because of the 'auto' type of the const variable) 
  and
 cannot be changed in any of the following assignment statements to 
 the const
 variable.

 2.
 Here for the structure struct s1 since the entire structure is
 ending within 8 bytes no padding is done which means
 s1: [char a]
1byte
 but for the structure struct s2 consider the following:
 s2: [ char a
 1byte
-- int a---
--4bytes]
 so here the concept of padding comes to make all the variable
 aligned in even boundaries and so the structure after aligning will 
 look as:
 s2: [ -- char b
 --4byte-
-- int a---
--4bytes]

 so the size of strcut s2 will be 8bytes..

  --
 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/-/FoHpgvrjnm0J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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 this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at