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 question.(5)

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

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/How to fix “warning: control reaches end of non-void function c++”
Next
Answered
Léna Bigot
  • 11
Léna Bigot
Asked: May 17, 20222022-05-17T13:15:20+00:00 2022-05-17T13:15:20+00:00In: c

How to fix “warning: control reaches end of non-void function c++”

  • 11

. Advertisement .

..3..

. Advertisement .

..4..

The error “control reaches end of non-void function” occurred when I run the C codes. I’ve tried to fix it for some days but have not resolved it yet. Can someone suggest a relevant solution to fix the warning: control reaches end of non-void function c++ issue? Much appreciate your support.

int main(void) {}
non-void function c++
  • 3 3 Answers
  • 138 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

3 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    Raphaël Ledoux
    2022-05-17T13:15:23+00:00Added an answer on May 17, 2022 at 1:15 pm

    As indicated in, the return-type for int is used in the main function.

    int main(void)

    However, your main function doesn’t return any information. It closes after

    puts(strB);

    Add

    return 0;

    It will all work after that.

    • 23
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Ambre Collet
    2022-05-17T13:15:27+00:00Added an answer on May 17, 2022 at 1:15 pm

    You can also use a C99 compiler instead of the obvious return statement being added to main().

    C99 allows main() to not have a return declaration, and the } implicitly returns 0.

    $ gcc -c -Wall t.c
    t.c: In function ‘main’:
    t.c:20: warning: control reaches end of non-void function
    $ gcc -c -Wall -std=c99 t.c
    $ 

    Purists will consider this important: not correct the warning by declaring main() as returning type void.

    • 10
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. ferneparker
    2022-07-12T06:41:54+00:00Added an answer on July 12, 2022 at 6:41 am

    This warning is identical to that described under Return with no value. GCC assumes that control has reached the end of a function without encountering a return value. This is because the function must return a value. Add a return statement at the end of each function that returns a suitable value even if control is never reached.

    int main(void)
    {
      // do something  
      return 0;
    }
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

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.