Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics (Retired) Functional Programming in C Conditionals - Switch

1 Question on Conditionals- Switch

My question remains on the switch case, I know it is basically switch(enter the var_name you want to compare) case (value you wanted to put to compare with): and break; 1stly, can the case been put of a variable instead of a value. I tried but can't. I check the documentation it says that it can only accept integer value, from what i know a char is not integer but how could a letter be int, and be accepted? And why in the case if the variable is integer type, why can't we put it into the case?

I have tried in the int a = 'b', I have figure out maybe somehow a letter can be interpreted as number, my question is how does computer determine which letter is which number? My second question as well is why when we char a = 'ac', it will be consider the value as c?

1 Answer

Guillaume Maka
PLUS
Guillaume Maka
Courses Plus Student 10,224 Points

a char is a single character, so

char a = 'ac'; // 'a' contain the last character -> 'c'

// To make a string, you need to declare an array of char
char[] a = 'ac';