What is function in C++?

by 11 replies
13
Please explain me with example.Thanks in advance.
#programming #function
  • The return value is actually very simple, you have some sort of function as a function of the black box, call the function, it passed into the function equivalent to the required data, and then start the function by its function runs, the final output the results of a run, the output result is the return value. But different functions for different functions.
    • [1] reply
    • A function is a group of statements that is executed when it is called from some point of the program. The following is its format:

      type name ( parameter1, parameter2, ...) { statements }

      where:
      type is the data type specifier of the data returned by the function.
      name is the identifier by which it will be possible to call the function.
      parameters (as many as needed): Each parameter consists of a data type specifier followed by an identifier, like any regular variable declaration (for example: int x) and which acts within the function as a regular local variable. They allow to pass arguments to the function when it is called. The different parameters are separated by commas.
      statements is the function's body. It is a block of statements surrounded by braces { }.
  • Ha ha... pretty theoretical tough. But, there are lot more books which can explain functions to you in a better way!
    I have a good knowledge on object oriented programming. I would suggest you to look things in a object oriented way rather than knowing "function in C++".
    Figure out what a function in a OO world. corolate it with C++. You will get to know the taste of the language!
    • [2] replies
    • C++ is an object orient programming language. That means there are items known as objects. This can be anything from a character in a video game to a combo box in a business application. Just like an object in real life these objects can perform actions and have actions performed on them. These actions are known as functions. All a function really is, is a grouping of code that makes sense to together.

      Example
      My object is a combo box.

      Now if I want I can create a line of code that will listen for the user to send input (i.e. press a button on the keyboard). Then I can write a line of code that takes this input stores it in a variable in memory. I then take that variable in memory and do a calculation on that variable. The new calculation I place in the combo box.

      Ok as you can see that is a lot of code so rather than recoding that every time I place all of that in a function called TranslateInput(). Now whenever I want my program to translate the user input I just place TranslateInput() in my code rather than all of those separate lines of code.


      If you have any other C++, C#, VB.NET, OpenGL, or XNA questions feel free to pm me or post them here. (Can't pm you back quite yet. I need 4 more posts.)
      • [ 1 ] Thanks

    • If you have a good knowledge then can you suggest me any good online tutorial for c++?
      • [2] replies
  • Banned
    [DELETED]
  • Features are the building blocks of the programmes. They make the programs more modular and easy to read and manage. All C++-programs must contain main () function. The implementation of the programme begins with the main () function. A C++ program can have any number of functions in accordance with the needs. The General form of the function is:-


    return_type function_name(parameter list)
    {
    body of the function

    }
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • A function is a group of statements which perform some operation on data being passed to it and can also return the result of operation. A function can be called at any step in a program. Functions provide reusability and modularity.

    Function definition:
    return_type_of_function function_name(function parameters)
    {
    //function body
    return statement, if any
    }

Next Topics on Trending Feed