One thing to remember is that, *sizeof* operator does not evaluate the expression used as the parameter, it only evaluates type of the parameter. So, in case 2, sizeof(a) ==> sizeof(int) ==> 4. We never actually access 'a'
Regards, Sandeep Jain Member of Technical Staff, Adobe Systems, India On Sun, Jul 3, 2011 at 3:13 AM, HARSH PAHUJA <[email protected]>wrote: > thanx i got it :) > > > On Sat, Jul 2, 2011 at 1:57 PM, santosh mahto <[email protected]>wrote: > >> this will help >> >> ->sizeof operator only need declaration not definition.since sizeof >> operator calculates size at >> compile time. >> At compile time code doesnot seek for definition.it only need >> declaration.if any variable is declared with extern,it thinks that >> its definition will be found at linking time. >> >> In ur question: >> 1 case. when a =20 is done compiler see that its value is declared.so its >> OK .but at link time since def of a is not found >> so linker error. since linker tries to find the actual memory address >> where the def of a is. >> >> see after compilation the symbol table for a will be as >> >> symbolname| memory location| value >> a |find later(garbage)| 20 >> >> so there is no problem with compiler .but at link time garbage value need >> to be filled with actual memory address >> since def is not there so linker error. >> >> case2. there will be noentry in the symbol table for a. as code doesnot >> include any defintion related operation. >> >> >> iF anything helps you, dont forget to say thanks >> >> Thanks >> Santosh >> >> >> >> >> >> On Sun, Jul 3, 2011 at 1:38 AM, HARSH PAHUJA <[email protected]>wrote: >> >>> will ny1 xplain this extern concept.... >>> y this is a linker error? >>> >>> >>> On Sat, Jul 2, 2011 at 12:49 PM, HARSH PAHUJA >>> <[email protected]>wrote: >>> >>>> @piyush plz explain how are u getting this...... >>>> >>>> >>>> On Sat, Jul 2, 2011 at 12:10 PM, Piyush Sinha <[email protected] >>>> > wrote: >>>> >>>>> i) [Linker error] undefined reference to `a' >>>>> >>>>> ii) 4 >>>>> >>>>> On 7/3/11, HARSH PAHUJA <[email protected]> wrote: >>>>> > 1) >>>>> > #include<stdio.h> >>>>> > int main() >>>>> > { >>>>> > extern int a; >>>>> > a=20; >>>>> > printf("%d",sizeof(a)); >>>>> > return 0; >>>>> > } >>>>> > >>>>> > 2) >>>>> > #include<stdio.h> >>>>> > int main() >>>>> > { >>>>> > extern int a; >>>>> > printf("%d",sizeof(a)); >>>>> > return 0; >>>>> > } >>>>> > >>>>> > >>>>> > >>>>> > -- >>>>> > HARSHIT PAHUJA >>>>> > M.N.N.I.T. >>>>> > ALLAHABAD >>>>> > >>>>> > -- >>>>> > You received this message because you are subscribed to the Google >>>>> Groups >>>>> > "Algorithm Geeks" group. >>>>> > To post to this group, send email to [email protected]. >>>>> > To unsubscribe from this group, send email to >>>>> > [email protected]. >>>>> > For more options, visit this group at >>>>> > http://groups.google.com/group/algogeeks?hl=en. >>>>> > >>>>> > >>>>> >>>>> >>>>> -- >>>>> *Piyush Sinha* >>>>> *IIIT, Allahabad* >>>>> *+91-8792136657* >>>>> *+91-7483122727* >>>>> *https://www.facebook.com/profile.php?id=100000655377926 * >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to [email protected]. >>>>> To unsubscribe from this group, send email to >>>>> [email protected]. >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>> >>>>> >>>> >>>> >>>> -- >>>> HARSHIT PAHUJA >>>> M.N.N.I.T. >>>> ALLAHABAD >>>> >>>> >>>> >>> >>> >>> -- >>> HARSHIT PAHUJA >>> M.N.N.I.T. >>> ALLAHABAD >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> 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 [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > HARSHIT PAHUJA > M.N.N.I.T. > ALLAHABAD > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
