1.How many characters are in the following string constant?
" \ t To continue, press the \"RETURN\" key\n"
Ans: total 38
27 normal characters
five blank spaces,
one special character(,)
four escape sequences (horizontal tab, two quotation marks and newline)
and the null character (\ 0) at the end of the string.
2.Which of the following are not valid identifires?
4th , _radius, value, the_tax_return,"My_name", area of circle
Ans. 4th,"My_name",area of circle
3.What is the differences between string constant "A"and character constant 'A'.
Ans. a character constant has an equivalent integer value, whereas a single-character string constant does not have an equivalent integer value and, in fact, consists of two characters -the specified character followed by the null character ( \ 0).
4.What will be the output of following programme?
char array[11] = "Hello World";
printf("%s\n",array);
Ans. Error
5. The unary operator always preceeds their operands (Trur/False)
Ans. Flase
i++,i-- are examples where unary operators comes after the operands
6. Write the unary operators.
Ans. ++,--,(type),sizeof,-,!
7. While considering the operators precedence and associativity , what is the difference between precedence and associativity?
Ans. Precedence tells the priority order of the operators in any expression.but ambuiguity arises while having same prirority opereators occur in same expression.In that case an order from either right to left or left to right is followed to resolve this problem.
For example :
in a=3+4-5
+ and - are of same priority.
then according to their associativity(Left to right) their operation will be performed in that order. Hence first addition is performed then subtraction.
NOTE: In all the operators only unary operators ,conditional operators and assignment operators are having associativity from right to left.
8.What is the value of following expression?
i = 2 * 5 / 2
Ans. Since * and / are having same priority then according to their associativity left to right * operation is performed first.
hence i=2*5/2=10/2=5
if expression would be like this i = 2 * (5/2) then answer will be i=2*2=4
9. In what general category do the #define and #include statements fall?
Ans. Preprocessor Statement