Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C program confusing output

Tags:

c

#include<stdio.h>


int main(){

        int main =22;
        printf("%d\n",main);
        return 0;
}

output:22 I am defining main as function and variable both even though compiler is not giving error. It should give error "error: redefinition of ‘main’ " . I am not able to understand why this code is working.

like image 310
manish Avatar asked Dec 12 '22 06:12

manish


1 Answers

It will not give you an error because main is not a keyword. but main is define 2 times - Scoping rules come into play.

like image 148
Sadique Avatar answered Dec 30 '22 04:12

Sadique