C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Point Out Errors (Q.No. 1)
1.
Point out the error in the following program (if it is compiled with Turbo C compiler).
#include<stdio.h>
int main()
{
display();
return 0;
}
void display()
{
printf("IndiaBIX.com");
}
Answer: Option
Explanation:
In this program the compiler will not know that the function display() exists. So, the compiler will generate "Type mismatch in redeclaration of function display()".
To over come this error, we have to add function prototype of function display().
Another way to overcome this error is to define the function display() before the int main(); function.
#include<stdio.h>
void display(); /* function prototype */
int main()
{
display();
return 0;
}
void display()
{
printf("IndiaBIX.com");
}
Output: IndiaBIX.com
Note: This problem will not occur in modern compilers (this problem occurs in TurboC but not in GCC).
Discussion:
18 comments Page 2 of 2.
Shreya said:
1 decade ago
Hey please tell me that if the printf and scanf gives "should have a prototype" kind of errors then what to do.
Susmitha said:
1 decade ago
When should we suppose to write prototype declarations? is it compulsory?
Arya said:
1 decade ago
i run the program in the compiler but i did not get any error.why?
Multimeter said:
8 years ago
If we remove void In calling function, we will get the output.
Swetha said:
1 decade ago
What's the difference between turboc and gcc compiler?
Siva rama krishna said:
1 decade ago
What is the use of display(), return 0;
Vivek said:
1 decade ago
Why gcc compiler will not give error ?
Avinash said:
9 years ago
Guys stay away from turbo C compiler.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers