1. Become a Developer for CrazyEngineers - Apply NOW!

Tips For C++ Programmers - Read & Learn

Discussion in 'Computer Science | IT | Networking' started by Vishal0203, Aug 28, 2012.

  1. vikaskumar11233

    vikaskumar11233 Enthusiast

    Engineering Discipline:
    Automobile
    Hey, Every thing is clear to me, but I have a little doubt in void main() function. I learn that void returns nothing, then why do you say that it returns a garbage value. Please made this concept clear to me.
     
  2. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    Declaring main() as void doesn't mean that the program won't return anything. It means that the program may not return a fixed value (garbage value), i.e. it may not return 0 like in int main() (we return 0 or EXIT_SUCCESS at the end if we declare it as int).

    Every c/c++ program must return 0 to indicate its success. And, other reason is C/C++ programming standards. They say that int main() is the best way. (the reason i've explained you above)
     
    • Like Like x 1
  3. Indo European

    Indo European Newbie

    Engineering Discipline:
    IT
    The key to superior software engineering is to hub away from developing monolithic applications that do only one job, and focus on budding libraries. One way to think of libraries is as a program with many entry points. Every record you write becomes an inheritance that you can pass on to other developers. Just like in mathematics you expand little theorems and use the little theorems to hide the complexity in proving bigger theorems, in software engineering you develop libraries to take care of low-level details once and for all so that they are out of the way every time you make a deferent implementation for a variation of the problem.
     
  4. safiajen0055

    safiajen0055 Apprentice

    Engineering Discipline:
    IT
    Nice In

    Nice Information :)
    Thanks for sharing this Information With us :)
     
  5. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    and yeah, instead of fflush(stdin) before cin.get(), you can even use cin.sync()
    it avoids inclusion of another header file cstdio :)
     
  6. Ganesh MSD

    Ganesh MSD Apprentice

    Engineering Discipline:
    Computer Science
    Nice post.! It is so useful..!!
     
  7. Min1a1k1shi

    Min1a1k1shi Newbie

    Engineering Discipline:
    IT
    The tips herein do not only explain how to write better code, but rather, they present the rationale behind the new language rules. Obviously, there are many other perennial good tips that C++ programmers can benefit from. However, I'm sure that this collection will provide you with many insights and guidelines for professional, efficient, and bug-free C++while teaching you some new coding and design techniques
     
    • Agree Agree x 1
  8. Badbade Abhi

    Badbade Abhi Apprentice

    Engineering Discipline:
    IT
    Thank you Vishal sir.. In future further programming i will definitely follow your instruction...Hattsss of your knowledge sir...
    with regards,
    Abhi
     
  9. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    I hope you do! because most people say that they'll program in this way but no one actually does!
     
  10. Sanket0731

    Sanket0731 Newbie

    Engineering Discipline:
    Computer Science
    what is the meaning of the line 'using namespace std'?
    what are namespaces?
     
  11. simplycoder

    simplycoder Ace

    Engineering Discipline:
    Electronics & Communications

    Try to google up. Google is your best friend in most of the cases.
     
  12. zeeshanaayan07

    zeeshanaayan07 Apprentice

    Engineering Discipline:
    Computer Science
    C++ is the mother of language without c++ we can service coding in all web developer software. Thanks for sharing a great post. I appreciate your thinking.
     
  13. vikaskumar11233

    vikaskumar11233 Enthusiast

    Engineering Discipline:
    Automobile
    Okay now i got it Vishal, thank you for solving my problem void main() declaration. I want to know more about the standard libraries and their declaration. Like I was making a program of AND and NAND gates but it was showing error in Library file declaration. Is there any need of some other standard libraries declaration which I was missing in this program ?
     
  14. Neeraj Sharma

    Neeraj Sharma Ace

    Engineering Discipline:
    Computer Science
    Can you share a code snippet of where exactly you were facing the problem?
     
  15. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    I'm unable to visualize need a snippet. If not the exact code post an example similar to it!
     
  16. zeeshanaayan07

    zeeshanaayan07 Apprentice

    Engineering Discipline:
    Computer Science
    I think this the c++ coding
     
  17. Neeraj Sharma

    Neeraj Sharma Ace

    Engineering Discipline:
    Computer Science
    I know its C++ coding. I want him to post the part of the code he is facing problems with.
     
  18. zeeshanaayan07

    zeeshanaayan07 Apprentice

    Engineering Discipline:
    Computer Science
    Learn C++ Coding because this is the basic thing which the base of all coding like html, css, php, csharp etc. if you want to learn c++ tutorial click there are the brilliant tutorial
     
  19. Neeraj Sharma

    Neeraj Sharma Ace

    Engineering Discipline:
    Computer Science
    I guess you don't understand what I am asking him. I know C++ since a lot of years.
    I would recommend you to read my posts and understand it before giving your advice.
     
  20. Indo European

    Indo European Newbie

    Engineering Discipline:
    IT
    Suppose you declare something like this in your code:
    const int* ptr=new int;
    To who is constantans is bided? Pointer or Pointed object? The ans is pointed object. So the following is legal:
    int u;
    int v;
    const int* ptr=&u;
    ptr=&v;//OK, pointer can be changed
    But not the following:
    int u=3;
    const int* ptr=&u;
    *ptr=4;//error, pointer is declared to address const int
    As pointer is being declared to point to const object and not itself being const, it can be declared without being initialized:
    const int* ptr;//Ok, no initialization of ptr needed.
    Now, suppose you want to declare pointer itself to be constant, so that the pointer cannot change its value and hence, will point only one object during its existence. Most of us will declare following when asked to do this for the first time in our life:
    int const* ptr;

    But this means the same as above, ptr happens to address a constant object. To declare pointer itself to be constant, use the following segment:
    int* const ptr=&someint;

    Now you can't make ptr to point to something else, but you can change the value of the object being pointed by it. To declare a const pointer which points to an const object any of the two segment is ok:
    int x=2;
    const int* const ptr1=&x;
    int const* const ptr2=&x;

    Passing one or more argument to a function as const: When you pass an argument to a function as const, it doesn't mean that you can't pass non-const object as an argument to that object. Only thing you are telling the compiler is that this variable has to retain its value during the execution of that function. So, if by mistake you try to change its value inside the function code, compiler will flag error.
    void somefunc(const int num){
    //...
    ++num;//OOPs, by mistake, But compiler will show it as an error
    //saving your precious time from hunting for the possible bug here
    //..
    }
     

Share This Page