what is the different between if-else and switch statment
(other than syntax)
Answers were Sorted based on User's Feedback
Answer / mohemmed bilal
main difference between both statement is that we can only
use switch for one variable eg
switch(x)
{
case 1://do this;
case 2://do this;
case 3://do this;
}
while in if else we can use multiple condition like
if(x==0&&y==0)
{
printf("");
}
else if(x==1&&y==0)
{
printf("");
}
| Is This Answer Correct ? | 0 Yes | 0 No |
if else
is nothing but private variables.
structure is nothing but continuous allocation and public
variables and dissimilar data type.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / nabila
if else use only the statements that are in two condition
switch atatements use different cases
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / bakhtiar khan wazir
IF Statement: Checks the value of data is less than or greater than. (in ranges).
example: can tell wether an input age is more than 18 and less than 60.
Switch Case: Checks the value of data that is prespecified. only equal to.
example: Can only generate output if the value matches. When the age is 18 or when the age is 60 . No comarison of data based on greater than or smaller than. Compares data based on equality.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / srinivasa reddy
Internally IF-ELSE implements Linear search, where as
SWITCH implements Binary search.
| Is This Answer Correct ? | 35 Yes | 51 No |
Answer / subbu
Basically while coding developers prefer Switch rather than
If-Else.
But inturn switch gets transferred to IF-ELSe format during
compilation.
| Is This Answer Correct ? | 31 Yes | 87 No |
52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2?
25 Answers Datamatics, Solartis, TCS, ThinkBox, Trine,
Describe the order of precedence with regards to operators in C.
fn f(x) { if(x<=0) return; else f(x-1)+x; }
What are unions in c?
Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates
What is the difference between ++a and a++?
How can type-insensitive macros be created?
What is the result main() { char c=-64; int i=-32 unsigned int u =-16; if(c>i){ printf("pass1,"); if(c<u) printf("pass2"); else printf("Fail2");} else printf("Fail1); if(i<u) printf("pass2"); else printf("Fail2") } a)Pass1,Pass2 b)Pass1,Fail2 c)Fail1,Pass2 d)Fail1,Fail2 e)none
9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro?
whats the use of header file in c?
main() { clrscr(); } clrscr();
related proverb of "dont count your chicken before it hatches"