C Programming and Problem Solving
Questions 241 to 250
241.
|
What is the meaning of the following
declaration?
char
(*(*x())[])();
|
||||||||||
What can be said of the following program and its
output?
void main()
{
enum
Months {JAN =1,FEB,MAR,APR};
Months
mon = JAN;
if(
mon = = 1)
printf("Jan
is the first month");
else
printf("Feb
is the first month");
}
|
|||||||||||
#define VALUE 1+2
main() {
printf("%d
and %d\n",VALUE/VALUE,VALUE*3);
}
What
will be the out come of above program?
|
|||||||||||
The outcome of the following program is:
void
main(){
int
const * ptr=5;
printf("%d",++(*ptr));
}
|
|||||||||||
The output printed for the following piece of code is:
void main( )
{
char str[ ]="MCA";
int
i;
for(i=0;str[
i ];i++)
printf("\t%c%c%c%c",str[
i ],*(str+i),*(i+str),i[str]);
}
|
|||||||||||
The output of the following code component is:
main() {
static
int var = 5;
printf("%d
",var--);
if(var)
main();
}
|
|||||||||||
Look at the following program and chose the right
option for it:
main() {
extern int i;
i=20;
printf("%d",i);
}
|
|||||||||||
The correct option for the following code segment is:
main()
{
int
a=-1, b=-1, c=0, d=2, e;
e
= a++&&b++&&c++||d++;
printf("%d
%d %d %d %d", a, b, c, d, e);
}
|
|||||||||||
The following program’s output is:
void main() {
int i;
clrscr();
printf( "%d", sizeof int
);
}
|
|||||||||||
The following program’s output is:
register int i;
void main()
{
clrscr();
printf( "%d", i );
}
|
Answers
A
|
According to the definition of pointers.
|
|
b
|
As the member JAN of enumerator Months is assigned a
value 1. Also the variable mon of type enumerator is assigned with JAN, so
mon gets the value of 1
|
|
d
|
Because of the macro replacement it becomes 1+2/1+2,
1+2 * 3. Therefore because of the operator precedence it is 5, 7
|
|
c
|
ptr is a
pointer to a "constant integer". But we tried to change the value
of the "constant integer". The error is Compiler error: Cannot
modify a constant value.
|
|
e
|
str[i], *(i+str), *(str+i), i[str] are all different
ways of expressing the same idea. Generally array name is the base address
for that array. Here str is the
base address. i is the index
number/displacement from the base address. So, indirecting it with * is same
as str[i]. i[str] may be surprising. But in the case of C it is same as
str[i].
|
|
d
|
When static
storage class is given, it is initialized once. The change in the value of a static variable is retained even
between the function calls. Main is also treated like any other ordinary
function, which can be called recursively
|
|
e
|
extern storage class in the following declaration,
extern int i;
specifies to the compiler that the memory for i is allocated in some other program
and that address will be given to the current program at the time of linking.
But linker finds that no other variable of name i is available in any other program with memory space allocated
for it. Hence a linker error has occurred. The error is Linker Error : Undefined symbol '_i'
|
|
b
|
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 ‘a++ && b++ && c++’ 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
|
|
d
|
The sizeof operator without parenthesis can be applied
only to variables but not the datatypes
|
|
c
|
Global variables are load time variables. Register
variables are stored in CPU. Hence register variables can’t be declared as
global variables, but must be declared as local only
|
No comments :
Post a Comment