1. what is the error in the following sequence of program. int i1; switch(i1) { printf("The value of I1 is :"); case 1: printf("%d",i1); break; case 2: printf("%d",i1); break; default : printf("Invalid entry"); }
when u have declared i1 has int no memory is allocated for that you must initalize it as for eg.., int i1=5;
Completely wrong. when you declare int i1 memory is allocated but not initialized. i1 is not a pointer but a variable here.
sir my intention of writing that is memory is allocated only when it is defined when we have given int i 'i' value and its address vary from compiler to compiler so i have written in the above way
Dear Mr. gpk kishore Thanks for your post on the forum. They have been very helpful with my assignment. You are a very good computer programmer and really appreciate your help. Carry on your good work Mehul
i1 is not initialised.so switch statement won't be able to know what the condition is.the whole program would be meaningless.
There's no need to initialize!!! You'll first have to get the value from the user so that the values can be compared.so it goes like this int i1; scanf("Enter the value of %d",i1); switch(i1); .................... Then the program will be perfect!!!
Code: #include<stdio.h> #include<conio.h> void main() { int i; printf("The value of I is :"); scanf("%d",&i); switch(i) { case 1: printf("%d",i); break; case 2: printf("%d",i); break; default : printf("Invalid entry"); } getch(); }