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<stdio.h>
int main(){
int num,count;
printf("\nEnter a number:");
scanf("%d",&num);
count=interrupt(num);
if(count==2)
printf("%d is a prime number",num);
else
printf("%d is not a prime number",num);
return 0;
}
int interrupt(int num){
int i,count=0;
for(i=1;i<=num;i++){
if(num%i==0)
count++;
}
return count;
}
Output: Compilation error
Explanation: interrupt is keyword of c language. It cannot be function name.
Definition of function in c
Name of function includes only alphabets, digit and underscore.
First character of name of any function must be an alphabet or underscore.
Name of function cannot be any keyword of c program.
Name of function cannot be global identifier.
Name of function cannot be exactly same as of name of function in the same scope.
Name of function is case sensitive
Name of function cannot be register Pseudo variable
No comments:
Post a Comment