RejinpaulPlacement
Search

Control Instructions - C Programming Questions and Answers - RejinpaulPlacement

@ : Home > C Programming > Control Instructions


Find us on Facebook



Follow us on Google+


Google+

1.
Which of the following cannot be checked in a switch-case statement ?
Answer & Solution
Answer: (C) Float
Solution: 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.
close
2.
In mathematics and computer programming, which is the correct order of mathematical operators ?
Answer & Solution
Answer: (B) Division, Multiplication, Addition, Subtraction
Solution: Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction).

Mnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS.
For more info: http://en.wikipedia.org/wiki/Order_of_operations
close
3.
Which of the following is not logical operator ?
Answer & Solution
Answer: (A) &
Solution: 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.
close
4.
What will be the output of the program?

#include
int main()
{
int i=0
for(; i<=5; i++);
printf("%d", i);
return 0;
}

Answer & Solution
Answer: (D) 6
Solution: Step 1: int i = 0; here variable i is an integer type and initialized to '0'.
Step 2: for(; i<=5; i++); variable i=0 is already assigned in previous step. The semi-colon at the end of this for loop tells, "there is no more statement is inside the loop".
Loop 1: here i=0, the condition in for(; 0<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 2: here i=1, the condition in for(; 1<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 3: here i=2, the condition in for(; 2<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 4: here i=3, the condition in for(; 3<=5; i++) loop satisfies and then i is increemented by '1'(one)
Loop 5: here i=4, the condition in for(; 4<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 6: here i=5, the condition in for(; 5<=5; i++) loop satisfies and then i is incremented by '1'(one)
Loop 7: here i=6, the condition in for(; 6<=5; i++) loop fails and then i is not incremented.
Step 3: printf("%d", i); here the value of i is 6. Hence the output is '6'.
close
5.
What will be the output of the program?

#include
int main()
{
int x = 3;
float y = 3.0;
if(x == y)
printf("x and y are equal");
else
printf("x and y are not equal");
return 0;
}

Answer & Solution
Answer: (A) x and y are equal
Solution: Step 1: int x = 3; here variable x is an integer type and initialized to '3'.
Step 2: float y = 3.0; here variable y is an float type and initialized to '3.0'
Step 3: if(x == y) here we are comparing if(3 == 3.0) hence this condition is satisfied.
Hence it prints "x and y are equal".
close