C++ gurus and learners, we program ourselves :P all work is CC licensed

Tuesday, November 5

Functions in C++

14:42 By

(Post from Hamza Iqbal)
A program is  a piece of code designed to solve a specific problem. In order to provide a solution to any problem a program must be divided into several tasks. Each task must then be further subdivided into a number of atomic(very basic tasks).
To emulate this behavior in programming we can use functions. Each function should ideally perform a single task, so when you are programming in c , c++ as a developer you must ensure this and if you feel that a function is performing multiple tasks then consider breaking down the function into several different functions.

How to define a function in C++
//Program explains use of functions

int sum(int firstNum, int secondNum)
/**
  * This is a sum function
  *It takes a two numbers(parameters) as input
  *it returns the sum of those numbers
  *This return value is given back to calling function
 **/
{
    return (firstNum + secondNum);
}

void sayHello()
/**
  *This function sayHello, prints Hello to console
  *This does not take input nor returns any value
 **/
{
    cout<<"Hello"<

4 comments :

  1. do give a read to this most important post here on function pointers till now. c++ function pointers are explained there pretty well

    ReplyDelete
  2. O Thankyou Sir ,,, I hope this is Start ,,, INSHALLAH Next will be more than this ,,,,

    ReplyDelete
  3. why have you not told about inline functions

    ReplyDelete