Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Return Statement in C| when I used print just after if condition it gave me "Equal multiple times" but when i used return statement it game me single time?

Return Statement in C| when I used print just after if condition it gave me "Equal multiple times" but when i used return statement it game me single time?

Scheduled Pinned Locked Moved C / C++ / MFC
game-devquestion
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14849246
    wrote on last edited by
    #1

    void main() {char name[50],came[50];int i; gets(name); gets(came); for(i=0;name[i]||came[i];i++) {int d=name[i]-came[i]; if(d==0) return printf("Equal"); else return printf("Unequal"); } }

    J L 2 Replies Last reply
    0
    • M Member_14849246

      void main() {char name[50],came[50];int i; gets(name); gets(came); for(i=0;name[i]||came[i];i++) {int d=name[i]-came[i]; if(d==0) return printf("Equal"); else return printf("Unequal"); } }

      J Online
      J Online
      jeron1
      wrote on last edited by
      #2

      Using return where you do, exits the current function you are in, in this case it is main(). So you are exiting the program when you call return.

      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

      1 Reply Last reply
      0
      • M Member_14849246

        void main() {char name[50],came[50];int i; gets(name); gets(came); for(i=0;name[i]||came[i];i++) {int d=name[i]-came[i]; if(d==0) return printf("Equal"); else return printf("Unequal"); } }

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You should read through every section of Organization of the C Language Reference | Microsoft Docs[^]. You will learn much faster than by posting questions here.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups