C Programming - Control Instructions - Discussion


Can we use a switch statement to switch on strings?

[A]. Yes
[B]. No

Answer: Option B


The cases in a switch must either have integer constants or constant expressions.

Rahul said: (Jan 13, 2012)  
I guess it works on strings.

We can write cases in the form of "case 'a':".

Priyanka said: (Mar 4, 2012)  
We can use switch along with string as a case also.

Kasak said: (Apr 15, 2012)  
@ all.
When we say case'a' its means a charcter not a string.
And switch dnt work on string.

Laxman said: (Dec 16, 2012)  
Why not character be a string because string is nothing but collection of characters?

Dheeraj Bajpai said: (Jun 13, 2013)  
Yes, it is true that string is collection of chars but it creates difference in the point of memory (char=1 byte, string=size of array). So string is not allowed.

Mritunjay said: (Aug 27, 2014)  
char is write like 'a'. But string is write like "a".

Pravin Pandhare said: (Aug 21, 2016)  
Here, we can write only char and int constant.

Anu said: (Dec 27, 2016)  
Please explain this briefly.

Tamil said: (Aug 16, 2017)  
Thanks @Dheeraj.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.