|
Solutions : Pointers - Part II
|
|
[Q001]
|
|
Ans. (d) When using macros with argument lists, you can merge (or paste) two tokens by separating them with ## (plus optional whitespace on either side), i.e. Token pasting with ##.
|
|
|
|
[Q002]
|
|
Ans. (c) Preprocessor directives can be defined anywhere in the program but just before its use.
|
|
|
|
[Q003]
|
|
Ans. (d) Preprocessor directives can be defined anywhere in the program but just before its use.
|
|
|
|
[Q004]
|
|
Ans. (a) Consider any function definitions (here it is 'main') in which DECLARATION OF VARIABLES
between the () and {} are LEGAL for specifying data types for FORMAL PARAMETERS ONLY. Otherwise
it is ILLEGAL or INVALID. Ex:- int c; in the above program is an ILLEGAL statement in C.
|
|
|
|
[Q005]
|
|
Ans. (b) A macro cannot call itself recursively.
|
|
|
|
[Q006]
|
|
Ans. (c) A const variable can be indirectly modified by a pointer as shown in the above program.
|
|
|
|
[Q007]
|
Ans. (c) The "stringizing" operator # allows a formal argument within a macro definition to be
converted to a string. Any special characters such as '," and \, will be replaced by their
corresponding escape sequences, Ex: \',\" and \\. In addition, the resulting string will
automatically be concatenated (combined) with any adjacent strings.
|
|
|
|
[Q008]
|
|
Ans. (b) The "stringizing" operator # allows a formal argument within a macro definition to be
converted to a string. The "token-pasting" operator ## causes individual items within a macro
definition to be concatenated, thus forming a single item.
|
|
|
|
[Q009]
|
|
Ans. (b) The "stringizing" operator # allows a formal argument within a macro definition to be
converted to a string. Consecutive whitespace characters inside the actual argument will be
replaced by a single blank space character.
|
|
|
|
[Q010]
|
Ans. (b) It is legal but ill-advised to use Turbo C++ keywords as macro identifiers.
In the above program : #define int float is legal, but possibly catastrophic.
|
|
|
|
[Q011]
|
|
Ans. (c) To skip over a data item without assigning it to the designated variable or array, the
% sign within the appropriate control group should be followed by an asterisk (*). This feature
is referred to as ASSIGNMENT SUPPRESSION.
|
|
|
|
[Q012]
|
|
Ans. (d) The variable 'val' is declared as static, hence memory for 'val' will be allocated for
only once, as it encounters the statement. The function main() will be called recursively unless
'val' becomes equal to 0, and since main() is recursively called, so the value of static
'val' ie., 0 will be printed every time the control is returned.
|
|
|
|
[Q013]
|
|
Ans. (a) The variable j is a block level variable and the visibility is inside that block only.
|
|
|
|
[Q014]
|
|
Ans. (c) The preprocessor directives can be redefined anywhere in the program. So the most
recently assigned value will be taken.
|
|
|
|
[Q015]
|
|
Ans. (a) #define statement defines symbolic constants in a C program. So the assigned value
cannot be altered using any operators instead it can be redefined anywhere in the program.
|
|
|
|
[Q016]
|
|
Ans. (b) *a and -*a cancels out. The result is as simple as 9 - 3 = 6
|
|
|
|
[Q017]
|
Ans. (c) Since i is static it is initialized to 0. Inside the while loop the conditional operator
evaluates to false, executing i--. Thus the integer value rotates to positive value (32767). Then
while condition becomes false and hence, comes out of the while loop, printing the i value.
|
|
|
|
[Q018]
|
|
Ans. (d) The boolean expression needs to be evaluated only till the truth value of the expression
is not known. Here <expr1>'s truth value is 1 or true. Because true || <expr2> where (expr2)
will not be evaluated. So the value of a remains the same. Thus a=5, b=7 & c=1
|
|
|
|
[Q019]
|
Ans. (c) The pointer ptr will point to the integer value in the memory location 0x1fa.
Ex: The value 5000 stored at 0x1fa and 0x1fb since size of integer value is 2 bytes. Similarly,the value 6000 stored at 0x1fc and 0x1fd.
|
|
|
|
[Q020]
|
Ans. (c) str[i] is same as i[str], str[i] is same as *(str+i), str[i+1] is same as *++(str+i)
Careful observation is necessary.
|
|
Back
|
|
Next
|
|