TAB

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Friday 29 January 2016

ASSESSMENT 1 MCQ

1.DIFFICULTY=HARD

Q.Scope of an external variable in C

a.Whole program where it is defined.
b.From the point of declaration to the point of end of file in which it is defined
c.Any source file that is linked.
d.From the point of declaration to the end of the file being compiled.

It must be (d). I am not entirely sure though.I will update once i get a confirmed explaination. Your answers with justification are always welcomed in the comments.

--------------------------------------------------------------------------------------------------------------------------
2.DIFFICULTY=EASY

Q.In the following loop construct which statement is executed only once.
for(exp1,exp2,exp3)

Sol. It has to be exp1 as it is the variable initialization which occurs only in the beginning .exp2 is the condition statement which is checked on every iteration and exp3 is the incrementation which is also executed everytime.

Ans. Exp1
--------------------------------------------------------------------------------------------------------------------------
3.DIFFICULTY=MEDIUM

Q.a=100 ;b=200;c=300
what will be the output of:
if(!a>=500)
b=300;
c=400;
printf("%d %d %d,a,b,c);

Sol. Firstly since the statement "c=400;" is outside the if block it will be executed irrespective of the if condition. Then the '!a' can be replaced with the ternary expression (a==0)?1:0. and then conpare the result with 500. Here since a is not 0 the value of !a is 0 which is not greater than or equal to 500 thus b=300 is never executed.

Ans.100 200 400

--------------------------------------------------------------------------------------------------------------------------
4.DIFFICULTY=EASY

Q. '&&' Operator in C is:

Ans : Logical AND
-------------------------------------------------------------------------------------------------------------------------
5.DIFFICULTY=HARD

Q. Character literals in C are denoted as :

Sol. Strings are represented in double-quotes ("example") and character in single quotes('c').

Ans. 'A'
--------------------------------------------------------------------------------------------------------------------------
6.DIFFICULTY=MEDIUM

Q.If a is an integer ,on executing a<<2 a becomes:

Sol. << is the left shift operator. It shifts the bits of the number in binary notation to the left side.
Example (101)<<1 becomes (1010)
and (1001)<<2 becomes (100100)
Thus here when a deimal number is converted to binary and left-shifted by 2 bits it gets "multiplied by 4"
Example : (2) in decimal is (10) in binary.Thus (10)<<2 is (1000) which corressponds to 8 in decimal system.

Ans. Multiplied by 4.
-------------------------------------------------------------------------------------------------------------------------
7.DIFFICULTY=EASY

Q.How many times will "Hello" be printed?

int i;
for(i=0;i<10;i++);
printf("Hello");

Sol. Common mistake is to say it will be printed "10 times" but actually we  miss the ';' at the end of the for loop in a hurry. Thus the body of the for loop is empty and "Hello" will be printed "only once"
Ans. 1 time.
--------------------------------------------------------------------------------------------------------------------------
8.Undefined function calls in C are detected by:

Sol.Refer : THIS. Correct me if i am wrong it must be "The Linker".

And."The Linker".
-------------------------------------------------------------------------------------------------------------------------
9.
Which keyword is used to come out of the loop for only that iteration.

Sol. The "continue" keyword is used for the following purpose.

Ans."continue"
------------------------------------------------------------------------------------------------------------------------
10. A bit field is :

Sol.Bit field in C is used to specify the width(of bits or bytes) required to store the variable.REFER THIS.

Ans. One Bit or a set of adjacent bits of a word.

------------------------------------------------------------------------------------------------------------------------
Please let me know in the comment if you have additional questions i will make sure to add them here.
And please do not hesitate to ask if you want further explaination on a particular solution,ill do my best.
As of the first question ,i will update as soon as i get a confirmed answer.








6 comments:

  1. for(;;)
    printf("%d",i);

    how many times the loop will run?

    ReplyDelete
  2. Infinite. It is a quick short cut for an infinite loop. But what is 'i' here?

    ReplyDelete
    Replies
    1. if i is 0, it wont even run once .....this was an incomplete question as the initial value of i was not given

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. is there no need for parenthesis while using an if conditioning statement?

    ReplyDelete
    Replies
    1. If the body of the "if"(or even "for") statement is only one line, parenthesis are not required.

      Delete