0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mistake > case文が意図通りに動かない > swtich文でdefaultがdefualt:になっている。

0
Last updated at Posted at 2015-06-20

引用: C++プログラミングの落とし穴 by Steve Oualline

以下のプログラムは意図通りに動かない。
何故か?

primeNumber.c
# include <iostream>
using namespace std;

int main() {
	int i;
    for(i = 2; i < 10; ++i) {
		switch(i) {
		case 2:
		case 3:
        case 5:
        case 7:
            std::cout << i << "is prime number" << std::endl;
			break;
		defualt:
           std::cout << i << "is not prime number" << std::endl;
			break;
		}
	}	 
	return 0;
}
2is prime number
3is prime number
5is prime number
7is prime number

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

答え

swtich文でdefaultがdefualt:になっている。
http://ideone.com/7fZ7fL
で実行した所、コンパイルも通る。

どうやらdefault:の代わりにdefualt:やthisIsTest:などにしてもコンパイルは通るようだ。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?