Home | Hindi | Kabir | Poetry | Workshop | BoloKids | Writers | Contribute | Search | Contact | Share This Page!                      Shop Online

  News
Channels
In Focus

Analysis  
Bolography  
Cartoons
Environment   
Opinion 

Columns
 Business
 My Word 
 PlainSpeak 
 Random Thoughts 
Our Heritage

Architecture
Astrology
Ayurveda
Buddhism
Cinema 
Culture
Dances
Festivals
Hinduism
History  
People  
Places 
Sikhism
Spirituality 
Vastu 
Vithika  

Society & Lifestyle

Family Matters 
Health
Parenting
Perspective 
Recipes
Society
Teens 
Women 

Creative Writings

Book Reviews
Ghalib's Corner
Humor
Individuality
Jagoji
Literary Shelf 
Love Letters  
Memoirs
Musings
Ramblings
Stories
Travelogues

Computing
  General Articles
 
CC++ 
  Flash 
  Internet Security 
 
Java 
 
Linux     
  Networking  

Computing | CC++   
Handling of Functions

We have seen that C functions by default return int value. This is obvious to raise a question , whether there are other return types for functions. Yes there are, not only the basic data types like int, float, char but also user-defined types like structures and arrays.  

For allowing other than the int return types we have the type-specifier for functions. This will help you  to return other return types. We must do two things to enable a calling function to receive a non-integer value from a called function: 

( NOTE: The following explanations are in accordance to the older method of C functions, which doesn't declare function arguments on the same line as the function header. The modern or ANSI  method declares the function on the same line as function header. There are also a few other subtle but important distinctions in the two methods. The latter method we will see later.)                        
1. The explicit type-specifier, corresponding to the data type required must be mentioned in the function header. The general form of the function definition is

 type-specifier  function-name (argument list)
 argument declaration;
{
 function statements;
}
The type-specifier tells the compiler, the type of data type the function is to return.

2. The called function must be declared at the start of the body in the calling function, like any other variable. This is to tell the calling function the type of data that the function is actually returning.

For example consider the following segment of program
main()
{
   float x,a,b, mul();              //function declaration
  double  y, div();                //function declaration
  //Program statements
  x = mul(a,b);                   //function call
  y = div(a,b);                   //function call
}

float mul(t,e)                    //function definition
float t,e;
{
  // Body
}

double div(i,o)               //function definition
float i,o;
{
  //body
}

The declaration part of main function declares not only the variables but the functions mul and div as well. This only tells the compiler that mul return a float-type value and div a double-type value. Parentheses that follow mul and div specify that they are functions instead of variables. 

If we have a mismatch between the type of data that the called function returns and the type of data that the calling function expects, we will have unpredictable results. We must, therefore be careful to make sure that both types are compatible.

In cases when the function doesn't return any values, in that situation we specify the return type as void. This  has to be done in the declaration of the function in the main as well in the function header.  

We will continue with few other function handling concepts  and start on the topic of variables in functions next time.   

– Sachin Mehta
September 23, 2001

C/C ++        
Managing Input-Output Operations
     
Managing Output Operations
    
Decision Making And Branching
     
Decision Making and Branching (if statement)
     
Decision Making and Looping
    
The Do Statement
   
Arrays
    
Arrays - Multi-Dimensional
    
Handling of Character Strings
    
Handling of Character Strings - 2  
User Defined Functions   
   User Defined Functions...contd    
Handling of Functions  

Computing
Flash | Internet Security 
Java | Linux | Networking  

General Articles  

Top | Previous 
 


 

Recommend This Page!

Analysis | Architecture | Astrology | Ayurveda | Book Reviews | Buddhism | Cartoons | Cinema | Computing | Culture | Dances
Environment | Fables | Family Matters | Festivals | Hinduism | Health | History | Home Remedies | Humor | Individuality | Jagoji
Literary Shelf | Memoirs | Musings | Opinion | Parenting | Perspective | Photo Essays | Places | Ramblings
Random Thoughts | Recipes | Sikhism | Society | Spirituality | Stories | Teens | Travelogues | Vastu | Vithika | Women

Home | Hindi | Bolography | BoloKids | Kabir | Poetry | Quotes | Workshop | Writers | Contribute | Search | Contact


Boloji.com is owned and managed by Boloji Media Inc

Privacy Policy | Disclaimer
No part of this Internet site may be reproduced without prior written permission of the copyright holder.