C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Yes / No Questions (Q.No. 2)
2.
Can we use a switch statement to switch on strings?
Yes
No
Answer: Option
Explanation:
The cases in a switch must either have integer constants or constant expressions.
Discussion:
9 comments Page 1 of 1.

Dheeraj bajpai said:   1 decade ago
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.

Kasak said:   1 decade ago
@ all.
When we say case'a' its means a charcter not a string.
And switch dnt work on string.

Laxman said:   1 decade ago
Why not character be a string because string is nothing but collection of characters?

Rahul said:   1 decade ago
I guess it works on strings.

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

Mritunjay said:   10 years ago
char is write like 'a'. But string is write like "a".

Priyanka said:   1 decade ago
We can use switch along with string as a case also.

Pravin pandhare said:   8 years ago
Here, we can write only char and int constant.

Anu said:   7 years ago
Please explain this briefly.

Tamil said:   7 years ago
Thanks @Dheeraj.

Post your comments here:

Your comments will be displayed after verification.