Syntax

C Switch Statement Syntax

In C, switch statement: branches on an integer value — switch (n) { case 1: ...; break; default: ...; }

Quick Answer

Syntax
switch (n) { case 1: ...; break; default: ...; }
CSyntax

Switch Statement

Code example
switch (n) { case 1: ...; break; default: ...; }

Branches on an integer value.

Learn More

How to switch statement in C

  1. Open your C file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C Switch Statement Syntax

Use switch (n) { case 1: ...; break; default: ...; }.

Related Syntax References

Frequently asked questions

What is the C syntax for switch statement?

Use this pattern: switch (n) { case 1: ...; break; default: ...; }

Can I copy this C code example?

Yes. Use Copy code and adapt the example to your program.

Is this C syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify