edited by
853 views
4 votes
4 votes

Consider the following code snippet

#include <stdio.h > 
main() { 
char a[10]; 
a[0] = 'a' ; 
abc(a); 
} 
abc( char a[]) { 
printf("%s",a[0]); 
}

According to my understanding when compiler reach line 5  ( abc function call in main) compiler assumes that abc is function with default int parameter and return type is int because function prototype is missing . But when compiler reach line 7 compiler contradicts the assumption and raise a compiler error.


But when I run output is printed.

 

What is wrong in my logic?

edited by

1 Answer

3 votes
3 votes
Standard for C was first made in 1989 called ANSI standard or ISO 90 standard and then updated in 1999 and then again in 2011. 1999 update was rarely used but 2011 update is more used.

The implicit return type assumption in C was there in 1989 standard but removed in 2011 standard. Now, any function must be properly prototyped before being used. Lets assume ANSI standard for now. If a function is not declared when compiler sees its usage- it assumes its return type as "int" and type of argument as that being passed. Now, when compiler sees the original function and its type is incompatible, it throws an error.

So far in GATE no question has ever been asked on any topic which has anything to do with standard.

Related questions

0 votes
0 votes
0 answers
2
gmrishikumar asked Jan 2, 2019
854 views
#include<stdio.h>int main ( ){ int demo ( ); // What is this and what does it do? demo ( ); (*demo) ( );}int demo ( ){ printf("Morning");}
2 votes
2 votes
1 answer
4