LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-06-2012, 11:13 AM   #1
batman4
Member
 
Registered: Jul 2012
Posts: 47

Rep: Reputation: Disabled
c program:Why this program is giving redeclaration error


Code:
main(){
display();
}
void display(){
printf("abc");
}
 
Old 12-06-2012, 11:38 AM   #2
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,079

Rep: Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110
I don't know why the compiler lets you declare main() that way (without void or a return type). But I think your problem is that using display() before declaring it implicitly declares it. Then the later definition doesn't match that implicit declaration.
 
Old 12-06-2012, 11:49 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,037

Rep: Reputation: 756Reputation: 756Reputation: 756Reputation: 756Reputation: 756Reputation: 756Reputation: 756
Because you didn't
Code:
#include <stdio.h>

void	display	(void);

main()
{
display();
}
void display()
{
printf("abc\n");
}
Hope this helps some.
 
Old 12-07-2012, 12:58 AM   #4
yahoosam
Member
 
Registered: Jun 2012
Posts: 79

Rep: Reputation: Disabled
Try always "int" with 'main'
closing 'main' with "return 0;"
 
  


Reply

Tags
programing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Program keeps giving me different answers carlosk711 Linux - Newbie 4 09-13-2012 10:14 AM
i am trying to write a php program n ends up giving me parse error on line 21 shygvy Programming 6 05-09-2012 10:11 AM
How To Use Java Program(.jar) As Start Up Service RHEL 5 Giving Error ?? mohsin2013 Linux - Newbie 1 01-31-2012 04:48 AM
Why is my program giving me segmentation fault? Ahmad Mujtaba Programming 5 12-25-2010 07:33 AM
[SOLVED] program to create a link list is giving an error jamesbon Programming 4 09-23-2010 07:12 AM


All times are GMT -5. The time now is 11:49 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration