Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324288
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:06:44+00:00 2026-05-21T09:06:44+00:00

I tried to compile following program with gcc. 0 #include <stdio.h> 1 2 main

  • 0

I tried to compile following program with gcc.

0 #include  <stdio.h>
1 
2 main ()
3
4 {    
5  char my_string[] = "hello there";      
6
7  my_print (my_string);    
8  my_print2 (my_string);    
9}
10   
11 void my_print (char *string)
12 {    
13  printf ("The string is %s\n", string);    
14 }
15        
16 void my_print2 (char *string)
17 {
18  char *string2;    
19  int size, i;   
20
21  size = strlen (string);    
22  string2 = (char *) malloc (size + 1);
23
24  for (i = 0; i < size; i++)    
25    string2[size - i] = string[i];
26
27   string2[size+1] = '\0';    
28   printf ("The string printed backward is %s\n", string2);    
29 }

However, it fails and the compiler produces following error log:

  1. greeting.c: 11: error:conflicting types for ‘my_print’
  2. greeting.c: 7: error: previous implicit declaration of ‘my_print’ was here
  3. greeting.c: 16: error:conflicting types for ‘my_print2’
  4. greeting.c:8: erroro:previous implicit declaration of ‘my_print2’ was there

And if I move the my_print and my_print2 functions before the main function, everything goes well.
So can anyone explain why the problem happens?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:06:44+00:00Added an answer on May 21, 2026 at 9:06 am

    If you don’t declare a function and it only appears after being called, it is automatically assumed to be int, so in your case, you didn’t declare

    void my_print (char *);
    void my_print2 (char *);
    

    before you call it in main, so the compiler assume there are functions which their prototypes are int my_print2 (char *); and int my_print2 (char *); and you can’t have two functions with the same prototype except of the return type, so you get the error of conflicting types.

    As Brian suggested, declare those two methods before main.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I compile a program using just gcc code.c There are no messages, and
iam beginner in Objective-C, i tried to compile small Hello world program to start,iam
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
Consider the following program: #include <iostream> #include <algorithm> using namespace std; template<class T> struct
I tried to compile the example posted ( C++ Service Providers ) and failed
I got this error when I tried to compile an application that includes the
I tried scouring the web for help on this issue, but there are so
I tried to package a Twisted program with py2exe, but once I run the
I am trying to use MinGW to compile a C program under Windows XP.
I am attempting to compile C code that utilizes the following within GNU readline.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.