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++   
User Defined Functions
... continued

We begin here, with the general structure functions in C have

function-name(argument list)
argument declaration;
{
 local variable declarations;
 executable statement1;
 executable statement2;
 ----------
 ----------
 rerturn (expression);
}             

All parts are not essential. Some may be absent. For example, the argument list and its associated argument declaration parts are optional. The declaration of local variables is required only when any local variables are used in the function.

A function can have any number of executable statements at all. For example:

do_nothing(){}

The return statement is the mechanism for returning a value  to the calling function. This is also an optional statement. Its absence indicates that no value is being returned to the calling function.    

Argument List

The argument list contains valid variable names separated by commas. The list must be surrounded by parenthesis. The argument variables receive values from the calling function, thus providing a means for data communication from the calling function to the called function. Some examples of functions with arguments are :

sachinrulz(a, b, c)
mayurrulz(s, d, f)

All argument variables must be declared for their types after the function header and before the opening brace of the function body. Example:

rait(x,y)
float x;
int y;
{
 --------  
 --------
}

Return Values And Their Types

A function may or may not send back any value to the calling function. If it does, it is done through the return statement. While it is possible to pass to the called function any number of values, the called function can only return one value per call, at the most we can have 

return 
or 
return(expression)

The first, the 'plain' return does not return any value; it acts much as the closing brace of the function. When a return is encountered, the control is immediately passed back to the calling function. An example of the use of a simple return is as follows:

if(error) 
return;

The second form of return with an expression returns the value of the expression. For example,

mul(x,y)
int x,y;
{
 int p;
 p = x*y;
 return(p);
}

We could have also combined the last two statements as follows:

return(x*y);

Now by default all functions return int type data. If a function wants to return some other type of value (can be float, character, string, structure, pointer, etc) whether it is user-defined or inbuilt data type, it can be achieved by giving a type specifier in the function header. Example:

double sum(w, r)
char rait(c)

When a value is returned it is automatically cast to the function's type. In functions that do computations using double, yet return int, the returned value will be truncated to an integer.

We will continue with the various categories in C functions, next time.   

– Sachin Mehta
June 9, 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 | Next 
 


 

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.