Showing posts with label nw. Show all posts
Showing posts with label nw. Show all posts

Thursday, 3 September 2009

What is Ellipsis or … in c ?



Ellipsis is there consecutive period (.) with no
white space. With the help of ellipsis we can write a function of variable
number of parameter. For example:



#include
int number(int a,...){
   return a;
}


int main() {
   int i;
   i=number(5,4,3,2,1);
   printf("%d",i);

  
return 0;
}

Output: 5





Ellipsis can be
used as a variable number of parameters or a variable which

Monday, 15 June 2009

Function recursion in C programming


Calling of same function
from its function body is known as function recursion. It is alternative of
loop. Any c program which is possible using loop it must be possible using
function recursion. Simple example:



Find the sum of all even
numbers from 0 to 20 using function recursion. Program:



int main(){

int total;

total=sum(2);

printf("%d",total);

return 0;

}

int sum(int i){

static 

Friday, 12 June 2009

Renaming of function in C programming




In c we can typedef the function declaration. It is useful when function declaration is too complex and we have to give any simple name or if we have to create more numbers of function of the same type.

typedef void govinda(int);

void main(){

    govinda one,two;

    one(1);

    two(2);

    getch();

}

void one(int x){

    printf("FROM ONE %d",x);

}

void two(int y){

    printf("\

Friday, 29 May 2009

function which is returning void data type

void ass();void main(){    clrscr();    ass();    getch();}void ass(){    int i,j;    for(i=0;i<5;i++){         for(j=0;j

function which is returning double data type

#includedouble math();void main(){    float num;    num=math();    clrscr();    printf("%.lf",num);    getch();}double math(){    double d=2.1;    d=ceil(d);    return d;}Output: 3

Function returning int data type in c programming.

void main(){ int max; max=max_value(); printf("Max of three: %d",max); getch(); } int max_value(){ int a=5,b=15,c=10; int max; max=(a>=b?a:b)>=c?(a>=b?a:b):c; return max; } Output: 15

Function which is returning char data type in c programming.

char find_character(); void main(){ char character; character=find_character(); printf("Character : %c",character); getch(); } char find_character(){ char * string="cquestionbank",temp; string+=3; temp=*string; return temp; } Output: e

Name of function cannot be any keyword of c program




In c programming language a function name cannot be any keyword of c language. Function name can be keyword of c++ but it is bad practice. If function name is keyword of c language we will cause of compilation error.



Example:



#include



int main(){

   int num,count;

   printf("\nEnter a number:");

   scanf("%d",&num);

   count=interrupt(num);



First character of name of any function must be either alphabets or underscore in c




First letter or character of a function's name must be either an alphabet or underscore. If function name start from any digits or any other special character then we will get compilation error.



Example 1:



#include

int main(){

   int min=1,max=100;

   int sum;

   sum= _digit_(min,max);

   printf("sum = %d",sum);

   return 0;

}

int _digit_(int min,int max){

   int total;