Control Instructions Questions And Answers.
Exercise ::
Control Instructions
1. How many times "PAK-MCQS" is get printed?
#include<stdio.h>
int main()
{
int x;
for (x=-1 ; x<=10 ; x++)
{
if (x < 5 )
continue ;
else
break ;
printf("PAK-MCQS" );
}
return 0 ;
}
A. Infinite times B. 11 times C. 0 times D. 10 times
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
2. How many times the while loop will get executed if a short int is 2 byte wide?
#include<stdio.h>
int main()
{
int j=1 ;
while (j <= 255 )
{
printf("%c %d\n" , j, j);
j++;
}
return 0 ;
}
A. 254 times B. 255 times C. 256 times D. Infinite times
View Answer
Discuss forum
Workplace
Report
Answer: Option B
Explanation:
The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.
See More Information
Tutorial Link:
Published by:Michael Daani
3. In mathematics and computer programming, which is the correct order of mathematical operators ?
A. Addition, Subtraction, Multiplication, Division B. Division, Multiplication, Addition, Subtraction C. Multiplication, Addition, Division, Subtraction D. Addition, Division, Modulus, Subtraction
View Answer
Discuss forum
Workplace
Report
Answer: Option B
Explanation:
Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction).
See More Information
Tutorial Link:
Published by:Michael Daani
4. Which of the following cannot be checked in a switch-case statement?
A. Character B. Integer C. Float D. enum
View Answer
Discuss forum
Workplace
Report
Answer: Option C
Explanation:
The switch/case statement in the c language is defined by the language specification to use an int value, so you can not use a float value.
See More Information
Tutorial Link:
Published by:Michael Daani
5. Point out the error, if any in the for loop.
#include<stdio.h>
int main()
{
int i=1 ;
for (;;)
{
printf("%d\n" , i++);
if (i>10 )
break ;
}
return 0 ;
}
A. There should be a condition in the for loop B. The two semicolons should be dropped C. The for loop should be replaced with while loop. D. No error
View Answer
Discuss forum
Workplace
Report
Answer: Option D
Explanation:
Step 1 : for(;; ) this statement will genereate infinite loop.Step 2 : printf("%d\n", i++); this statement will print the value of variable i and increement i by 1(one).Step 3 : if(i>10) here, if the variable i value is greater than 10, then the for loop breaks.
See More Information
Tutorial Link:
Published by:Michael Daani