Notices
Results 1 to 20 of 20
Like Tree3Likes
  • 1 Post By Strange
  • 2 Post By Strange

Thread: Can someone put an tutorial on functions in c++ please ??

  1. #1 Can someone put an tutorial on functions in c++ please ?? 
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    I m an 11th std student and 14 years old this is my first post and i want your help for understanding functions in C++
    can u help?


    Reply With Quote  
     

  2.  
     

  3. #2  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,670
    Do you mean functions in general?

    It is just a piece of code which is given a name and can operate on data and return a result. For example:
    Code:
    int add(int a, int b) {
      int sum;
      sum = a + b;
      return sum;
    }
    That is a simple function called "add" that adds two numbers and then returns the result. You can call it like this:
    Code:
    int x;
    
    x = add(4, 10);
    After that, x will have the value 14.

    There are lots of pre-defined libraries of functions to do things like arithmetic, string manipulation, file i/o, etc.

    Is that the sort of thing you want to know?


    Rajnish Kaushik likes this.
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  4. #3  
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    yep so can u give my more please
    Reply With Quote  
     

  5. #4  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,670
    More what?

    Functions? See here: C library - C++ Reference

    Or more explanation of how functions work? See here: http://www.cplusplus.com/doc/tutorial/functions/

    What do you want to know?
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  6. #5  
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    any possible thing about the functions
    Reply With Quote  
     

  7. #6  
    ▼▼ dn ʎɐʍ sıɥʇ ▼▼ RedPanda's Avatar
    Join Date
    Aug 2012
    Location
    UK
    Posts
    2,737
    Quote Originally Posted by Rajnish Kaushik View Post
    any possible thing about the functions
    Your request is a bit too 'general'.
    Could you perhaps try using the function Strange provided (and read the links he provided) and then come back with a more specific question?
    SayBigWords.com/say/3FC

    "And, behold, I come quickly;" Revelation 22:12

    "Religions are like sausages. When you know how they are made, you no longer want them."
    Reply With Quote  
     

  8. #7  
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    but that functions are a bit more higher level
    Reply With Quote  
     

  9. #8  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,670
    What exactly do you want to know that the links provided, Wikipedia, reference books, etc. don't tell you?

    One could write an entire book on the concept and implementation of functions. And several books on the libraries of functions available. I am not going to do that without getting paid.
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  10. #9  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    What I told my students was that functions answer a single question. For example "what is the sum of a and b?" Or "What is the average of this list of values?"

    But yeah, this is a discussion forum and not a class room, so you're not going to get a good answer to such a general question. You can ask as many specific questions as you want though, but it might take some time to go through them all (and you'll get the best answers if you ask them one or two at a time).
    Reply With Quote  
     

  11. #10  
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    i know a bit of function but i know c++
    Reply With Quote  
     

  12. #11  
    ▼▼ dn ʎɐʍ sıɥʇ ▼▼ RedPanda's Avatar
    Join Date
    Aug 2012
    Location
    UK
    Posts
    2,737
    Quote Originally Posted by Rajnish Kaushik View Post
    i know a bit of function but i know c++
    I get the feeling that you are not reading our replies.
    SayBigWords.com/say/3FC

    "And, behold, I come quickly;" Revelation 22:12

    "Religions are like sausages. When you know how they are made, you no longer want them."
    Reply With Quote  
     

  13. #12  
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    i do am
    Reply With Quote  
     

  14. #13  
    ▼▼ dn ʎɐʍ sıɥʇ ▼▼ RedPanda's Avatar
    Join Date
    Aug 2012
    Location
    UK
    Posts
    2,737
    Quote Originally Posted by Rajnish Kaushik View Post
    i do am
    We asked several questions and you have not answered them.

    If you do not understand a question, you can ask us to explain.

    But so far, we cannot answer your question because it is too broad.
    SayBigWords.com/say/3FC

    "And, behold, I come quickly;" Revelation 22:12

    "Religions are like sausages. When you know how they are made, you no longer want them."
    Reply With Quote  
     

  15. #14  
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    can you please repeat all the questions ?
    Reply With Quote  
     

  16. #15  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,670
    Quote Originally Posted by Rajnish Kaushik View Post
    can you please repeat all the questions ?
    There is really only one: what exactly do you want to know about functions?
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  17. #16  
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    they are used in C++ programs and contains a bracit and are outside of main
    Reply With Quote  
     

  18. #17  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,670
    Quote Originally Posted by Rajnish Kaushik View Post
    they are used in C++ programs and contains a bracit and are outside of main
    So, what is your question?
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  19. #18  
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    why do we need functions?
    Reply With Quote  
     

  20. #19  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,670
    They are useful for Structured programming:

    1. They break the program up into manageable and (hopefully) independent chunks of code.
    2. They break the function of the program into manageable units.
    3. They simplify testing, because you can test each function before you have written the entire program
    4. They avoid duplication of code. For example, if you want to calculate the average of a set of numbers, you could duplicate the code to do that in each place, but if you put it in a function then you only have to write it once.
    5. Because of this, they reduce errors.
    6. They allow for re-use (for example all the standard libraries mean that you don't have to write code to calculate sine or square root whenever you need it)
    7. They allow for efficiency: the standard math functions, for example can be written using very advanced "tricks" that the average programmer may not know, they might also be optimised for the specific target processor.
    8. Other things I haven't thought of ...


    Subroutine - Wikipedia, the free encyclopedia
    RedPanda and Rajnish Kaushik like this.
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  21. #20  
    Genius Idiot Rajnish Kaushik's Avatar
    Join Date
    Jan 2014
    Posts
    168
    thanks strange
    Reply With Quote  
     

Similar Threads

  1. TeX tutorial
    By JaneBennet in forum Mathematics
    Replies: 84
    Last Post: January 23rd, 2014, 07:01 PM
  2. Replies: 1
    Last Post: May 13th, 2013, 04:20 PM
  3. VRML tutorial
    By Noxstant in forum Computer Science
    Replies: 0
    Last Post: January 6th, 2010, 10:01 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •