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.

Tamil said:   7 years ago
Thanks @Dheeraj.

Anu said:   8 years ago
Please explain this briefly.

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

Mritunjay said:   1 decade ago
char is write like 'a'. But string is write like "a".

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.

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

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

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

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

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

Post your comments here:

Your comments will be displayed after verification.