• edited by
1,178 views
1 1 vote

Output of the following program?

#include <stdio.h>

char input[ ] = "SSSWILTECH1\1\11W\1WALLMP1";

main() {

int  i,c;

for( i=2 ; ( c=input[i] ) ! = '\0' ; i++) {

switch(c) {

case 'a' : putchar( 'i' );continue;

case '1' : break;

case 1 : while( ( c=input[++i] )!= '\1' && c!= '\0' );

case 9 : putchar( 'S' );

case 'E' :

case 'L' : continue;

default : putchar (c);

continue;

}

putchar( ' ' );

}

putchar( '\n' );

}

1 Answer

Best answer
1 1 vote
        #include <stdio.h>
        char input[ ] = "SSSWILTECH1\1\11W\1WALLMP1";
        int main(void) {
        	int i,c;
            for(i=2;(c=input[i])!='\0';i++){//Printing starts at a[2]
            switch(c) {
            case 'a' : putchar( 'i' );continue;
            case '1' : break;
            case 1 : while( ( c=input[++i] )!= '\1' && c!= '\0' );
            case 9 : putchar( 'S' );
            case 'E' :
            case 'L' : continue;
           default : putchar (c);
           continue;
            }
			putchar( ' ' );
			}
			putchar( '\n' );
        	return 0;
        }

Printing starts at a[2]=S, and case S is by default print S. 'L' and 'E' executes continue statements.

• selected by
Position:
Show:

Related questions

2 2 votes
2 2 answers
2.5k
2.5k views
Hira Thakur asked Sep 14, 2018
2,540 views
int main() { int a =50; switch(a) { default: a=45; case 49: a++; case 50: a ; case 51: a =a+1; } printf("%d",a); }my doubt is the default case is not executed here why??,...
0 0 votes
1 1 answer
925
925 views
joshi_nitish asked Jun 28, 2017
925 views
BREAK can be used in switch-case but CONTINUE is not allowed in switch-case but CONTINUE is allowed in DEFAULT case of switch-case..is it correct??
10 10 votes
1 1 answer
338
338 views
GO Classes asked Jun 3
338 views
What is the output of the following code?#include <stdio.h int main() { int x = 2, y = 0; switch (x) { case 1: y = y + 1; case 2: y = y + 2; case 3: y = y + 3; break; def...
7 7 votes
2 2 answers
501
501 views
Cutoff_Breaker asked Jul 10
501 views
What is the output given exp = 4?switch (exp){ default: printf("default\n"); case 5: printf("5\n"); case 3: printf("3\n"); case 2: ...