[algogeeks] C++ Doubts !!
Q1) What does the compiler does if I declare a base class VIRTUAL ?? Q2) In the below test code , class A : public B, public C { }; The order of constructor invocation is : B C A but if C is virtual base class the it changes to : C B A Why ?? Q3) Write a macro that swaps any data given to it (Eg: char , int , pointer of any kind , float ) -- 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/-/mj25b-AYRgAJ. 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] C++ Doubts !!
Dude google C++ Faqs. You will find all your answers. You can also buy some books 1. C++ Common Knowledge: Essential Intermediate Programming 2. Effective and More effective C++ 3. C++ gotchas On Sat, Sep 24, 2011 at 11:52 AM, Decipher ankurseth...@gmail.com wrote: Q1) What does the compiler does if I declare a base class VIRTUAL ?? Q2) In the below test code , class A : public B, public C { }; The order of constructor invocation is : B C A but if C is virtual base class the it changes to : C B A Why ?? Q3) Write a macro that swaps any data given to it (Eg: char , int , pointer of any kind , float ) -- 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/-/mj25b-AYRgAJ. 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.
[algogeeks] C Doubts
1.When I declare a variable as const then any subsequent assignment of it gives an error assignment of read only variable. Is a const variable treated as a read only variable? 2. #includestdio.h struct s1 { char a; }; char s2 { char b; int c; }; printf(%d,sizeof(struct s1)); // output : 1 printf(%d,sizeof(struct s2)); // output : 8 please explain.. -- 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/-/nOK4AkuAgW8J. 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] C Doubts
1. Yes, you cannot modify a const variable. This itself means that it is read-only. 2.Google structure padding. It is done to make sure that variables start in memory at addresses that are a multiple of their size. This is more efficient at hardware level. 'char' (1 byte) variables can be byte aligned and appear at any byte boundary. 'int' (4 byte) variables must be 4 byte aligned ( they can only appear at byte boundarys that are a multiple of 4 bytes). So, here char b --- At any available byte int c -- 3 bytes from b. So, a total of 1+3+4 = 8 bytes. On Sun, Jul 17, 2011 at 11:38 PM, Abhi abhi123khat...@gmail.com wrote: 1.When I declare a variable as const then any subsequent assignment of it gives an error assignment of read only variable. Is a const variable treated as a read only variable? 2. #includestdio.h struct s1 { char a; }; char s2 { char b; int c; }; printf(%d,sizeof(struct s1)); // output : 1 printf(%d,sizeof(struct s2)); // output : 8 please explain.. -- 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/-/nOK4AkuAgW8J. 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. -- Best Regards, Harshal Choudhary 7th Semester, CSE Dept. NIT Surathkal, India. The road to knowledge runs through the land of confusion. Mobile: +91 9844667142 Email : hc4...@gmail.com http://www.facebook.com/profile.php?id=1518764305 https://twitter.com/#!/harshal4342 http://www.linkedin.com/pub/harshal-choudhary/17/731/291 http://kkoolharshal.blogspot.com -- 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] C Doubts
1) you cannot change the const variable . 2) generally sizeof behaviour in case of structure is just undefined. Either it follows the summation of size of members or it uses padding concept ie in your example 4 byte each for character(1 byte for char rest of the 3 bytes is padded up) and 4 byte for integer .This is more efficient On Sun, Jul 17, 2011 at 11:38 PM, Abhi abhi123khat...@gmail.com wrote: 1.When I declare a variable as const then any subsequent assignment of it gives an error assignment of read only variable. Is a const variable treated as a read only variable? 2. #includestdio.h struct s1 { char a; }; char s2 { char b; int c; }; printf(%d,sizeof(struct s1)); // output : 1 printf(%d,sizeof(struct s2)); // output : 8 please explain.. -- 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/-/nOK4AkuAgW8J. 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] C Doubts
That was really helpful. -- 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/-/KvxrTcPf104J. 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.