Sunday, November 28, 2010

QUESTIONS ON CONTROL STRUCTURES


1. 
How many times "IndiaBIX" is get printed?
#include<stdio.h>
int main()
{
    int x;
    for(x=-1; x<=10; x++)
    {
        if(x < 5)
            continue;
        else
            break;
        printf("IndiaBIX");
    }
    return 0;
}
A.Infinite timesB.11 times
C.
0 times
D.10 times
Answer: Option C
Explanation:
No answer description available for this question. Let us discuss.


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.Infinite timesB.
255 times
C.256 timesD.254 times
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.


3. 
Which of the following is not logical operator?
A.
&
B.&&
C.||D.!
Answer: Option A
Explanation:
Bitwise operators:
& is a Bitwise AND operator.
Logical operators:
&& is a Logical AND operator.
|| is a Logical OR operator.
! is a NOT operator.
So, '&' is not a Logical operator.


4. 
Which is the correct order of mathematical operators ?
A.Division, Multiplication, Modulus
B.
Division, Multiplication, Subtraction
C.Modulus, Addition, Division
D.Addition, Division, Modulus, Subtraction
Answer: Option B
Explanation:
Simply called as BODMAS (Bracket of Division, Multiplication, Addition and Subtraction).


5. 
Which of the following cannot be checked in a switch-case statement?
A.CharacterB.Integer
C.
Float
D.enum
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.

switch( expression )
{
    case constant-expression1:    statements 1;
    case constant-expression2:    statements 2;    
    case constant-expression3:    statements3 ;
    ...
    ...
    default : statements 4;
}
The value of the 'expression' in a switch-case statement must be an integer, char, short, long. Float and double are not allowed.

No comments:

Post a Comment