Predict the output or
error(s) for the following:
%d %d %d",i,j,k,l,m);
0 0 1 3 1
Logical operations always give a result of 1 or 0 . And also the logical AND
(&&) operator has higher priority over the logical OR (||) operator. So the
expression ‘i++ && j++ && k++’ is executed first. The result of this
expression is 0 (-1 && -1 && 0 = 0). Now the expression is 0
|| 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 ||
0’ combination- for which it gives 0). So the value of m is 1. The values of
other variables are also incremented by 1.
The sizeof() operator gives the number of bytes taken by its operand. P is a
character pointer, which needs one byte for storing its value (a character).
Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the
address of the character pointer sizeof(p) gives 2.
case 1: printf("one");
case 3: printf("three");
The default case can be placed anywhere inside the loop. It is executed only
when all other cases doesn't match.
-1 is internally represented as all 1's. When left shifted four times the least
significant 4 bits are filled with 0's.The %x format specifier specifies that
the integer value be printed as a hexadecimal value.
void display(char *string)
Compiler Error : Type mismatch in redeclaration of function display
In third line, when the function display is encountered, the compiler doesn't
know anything about the function display. It assumes the arguments and return
types to be integers, (which is the default type). When it sees the actual
function display, the arguments and type contradicts with what it has assumed
previously. Hence a compile time error occurs.
int c=- -2;
Here unary minus (or negation) operator is used twice. Same maths rules
applies, ie. minus * minus= plus.
However you cannot give like --2. Because -- operator can only be applied
to variables as a decrement operator (eg., i--). 2 is a constant and not a
13. #define int
Since the #define replaces the string int by the macro char
In the expression !i>14 , NOT (!) operator has more precedence than ‘ >’ symbol.
! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14
is false (zero).
Page Numbers :