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 4541316
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:13:00+00:00 2026-05-21T15:13:00+00:00

Folks, Recently started learning C. Stuck at a point. Its about working of switch-case

  • 0

Folks,

Recently started learning C.
Stuck at a point. Its about working of switch-case statement.

Here’s the code :

#include<stdio.h>

int main() {
        int i=4;
        switch(i) {

                default :       
                        printf("%s","Default");
                case 0:         
                        printf("%s","Case 0");
                case 1:         
                        printf("%s","Case 1");
                case 2:         
                        printf("%s","Case 2");

        return 0;
        }
 }  

I personally think, “Default” should be printed, as it doesn’t match with any of case value.
But when I run the code in Turbo C, what I observed was this :

Default
Case 0
Case 1
Case 2  

Even same was observed here : http://www.ideone.com/pFh1d

What is the problem ? It is the compiler problem or any mistake in my code ?


EDIT :

PS : What wrong does it make if at all I have to write default case first. Any harm ?

But once the compiler knows that it has to execute the default statement, why we need to put a break statement after the statements of default case ?

  • 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-21T15:13:01+00:00Added an answer on May 21, 2026 at 3:13 pm

    The switch statement will jump to the appropriate case or default and then the code will continue until the next break statement.

    As your code has no break it will start off at the default: and simply continue through all the following statements. This can sometimes be a useful trick when programming similar conditions, but generally the lack of break statements will cause confusion.

    Also the final return is in the wrong place it should be after the switch statement.

    Amend as follows.

            int i=4;
            switch(i) {
    
                    default :       
                            printf("%s","Default");
                            break;
                    case 0:         
                            printf("%s","Case 0");
                            break;
                    case 1:         
                            printf("%s","Case 1");
                            break;
                    case 2:         
                            printf("%s","Case 2");
                            break;
    
            }
            return 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started learning Python and I was rather surprised to find a 1000
I've just recently started learning HTML/CSS and I've been trying to teach myself sound
Folks, I'm working on a little piece of rich client software that I'd like
What do folks here see as the relative strengths and weaknesses of Git, Mercurial,
I recently started diving into low level OS programming. I am (very slowly) currently
Introduction Hello folks, I recently learned to program in C! (This was a huge
Folks, I need a solution that allows drag-and-drop cell over the table. The cells
Folks, we all know that IP blacklisting doesn't work - spammers can come in
Folks, I connect to a large number of SQL Server 2005 databases through SQL
Folks, TIBCO has announced support for WCF channels back in April - has anything

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.