Function parameters in c


Function parameters in c programming

 
1.Default parameter of function is void.
 
2.Only register storage class is allowed with function parameter.

#include<stdio.h> 
int devD(register int,register int);
int main(){
    int temp;
    temp=devD(5,25);
    printf("%d",temp);
    return 0;
}

int devD(int register x,int register y){
    static int num;
    num=~x+y+1;
    return num;
}
 
Output: 20
 
3.Default storage class of function parameter is auto.
 
4.If function declaration has not written then during the function call it doesn’t check prototype of function if function return type is int data type and parameter is not float data type.
Examples:
 
(1) What will be output of following program?

#include<stdio.h>
int main(){
    call(2);
    return 0;
}  
int call(long int p,long int q, long int r){
    printf("%d %d %d",p,q,r);
    return 0;
}
 
Output: 2 garbage, garbage
 
(2) What will be output of following program?


#include<stdio.h>
void call(float,float,float);
int main(){
    call(5.0f);
     return 0;
}  
void call(float x,float y,float z){
    printf("%f %f %f",x,y,z);
}
 
 
Output: Error, too few parameters
 
(3) What will be output of following program?

#include<stdio.h>
int main(){
    call('A');
     return 0;
}  
int call(char x,char y,char z){
    printf("%c %c %c",x,y,z);
    return 0;
}
 
Output: A garbage, garbage
 
(4) What will be output of following program?


#include<stdio.h>
int main(){
    call(5);
    return 0;
}  
int call(int x,int y,int z){
    printf("%d %d %d",x,y,z);
    return 0;
}
 
Output: 5 garbage, garbage

Post a Comment