Name of function cannot be global identifier: Example

In c programming language name of function cannot be global identifiers. We function name will global identifiers then it will cause of compilation error.

(1) Program to find area of any circle.

#include <stdio.h>
#include <math.h>
float __radius__(float);

int main(){
   float r,a;
   printf("Radius of circle ");
   scanf("%f", &r);
   printf("%f\n", a);
   return 0;
float __radius__(float r){
   float a;
   a = M_PI * r * r;
   return a;

Above program is valid in c language. But it is bad practice to write the function name like __radius__ since this format is used for global identifiers.

(2) Program to find LCM of any two numbers.

#include <stdio.h>
int main(){
   int n1,n2,lcm;
   printf("\nEnter two numbers:");
   scanf("%d %d",&n1,&n2);
   return 0;
int __TIME__(int n1,int n2){
   int x,y;
   return x*y/n1;

Output: error
Explanation: Function name cannot be global identifier.

No comments: