Questions for: Control Instructions
#include<stdio.h>
int main()
{
int i = 10, j = 15;
if(i % 2 = j % 3)
printf("ExamAdept\n");
return 0;
}
if(i % 2 = j % 3) This statement generates "LValue required error". There is no variable on the left side of the expression to assign (j % 3).
#include<stdio.h>
int main()
{
int i = 10, j = 20;
if(i = 5) && if(j = 10)
printf("Have a nice day");
return 0;
}
"Expression syntax" error occur in this line if(i = 5) && if(j = 10).
It should be like if((i == 5) && (j == 10)).
Discuss About this Question.
#include<stdio.h>
int main()
{
int a = 10, b;
a >=5 ? b=100: b=200;
printf("%d\n", b);
return 0;
}
Variable b is not assigned.
It should be like:
b = a >= 5 ? 100 : 200;
Discuss About this Question.
#include<stdio.h>
int main()
{
void fun();
int i = 1;
while(i <= 5)
{
printf("%d\n", i);
if(i>2)
goto here;
}
return 0;
}
void fun()
{
here:
printf("It works");
}
A label is used as the target of a goto statement, and that label must be within the same function as the goto statement.
Syntax: goto <identifier> ;
Control is unconditionally transferred to the location of a local label specified by <identifier>.
Example:
#include <stdio.h>
int main()
{
int i=1;
while(i>0)
{
printf("%d", i++);
if(i==5)
goto mylabel;
}
mylabel:
return 0;
}
Output: 1,2,3,4
Discuss About this Question.
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case 1:
printf("Case1");
break;
case 1*2+4:
printf("Case2");
break;
}
return 0;
}
Constant expression are accepted in switch
It prints "Case1"
Discuss About this Question.
Discuss About this Question.