C Programming and Problem Solving Questions and Answers 241 to 250

C Programming and Problem Solving

Questions 241 to 250



241.
What is the meaning of the following declaration?
char (*(*x())[])();
(a)
x is a function returning pointer to array[] of pointer to function returning char
(b)
x is a function returning pointer to array[] of pointer to function returning pointer
(c)
x is a pointer returning pointer to array[] of pointer to function returning char
(d)
x is a function returning pointer to array[] of characters to function returning char
(e)
Invalid declaration.
242.
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");
}
(a)
Does not print anything
(b)
Jan is the first month
(c)
Generates compilation error
(d)
Results in runtime error
(e)
Feb is the first month.
243.
#define VALUE 1+2
main()     {
printf("%d and %d\n",VALUE/VALUE,VALUE*3);
}
What will be the out come of above program?
(a)
1 and 6
(b)
1 and 9
(c)
5 and 6
(d)
5 and 7
(e)
5 and 9.
244.
The outcome of the following program is:
void main(){
int  const * ptr=5;
printf("%d",++(*ptr));
}
(a)
Increments the value of ptr
(b)
Increments the address of ptr
(c)
Generates Compiler error
(d)
Generates runtime error
(e)
Prints 5 only.
245.
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]);
}
(a)
Generates runtime error
(b)
Generates Compiler error
(c)
MCA   MCA   MCA
(d)
MCA   MCA   MCA   MCA
(e)
MMMM   CCCC   AAAA.
246.
The output of the following code component is:
main()   {
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
(a)
5
(b)
Generates runtime error
(c)
Generates Compiler error
(d)
5 4 3 2 1
(e)
Infinite loop.
247.
Look at the following program and chose the right option for it:
main() {
extern int i;
i=20;
printf("%d",i);
}
(a)
20
(b)
  0
(c)
Garbage
(d)
Compilation error
(e)
Runtime error.
248.
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);
}
(a)
-1 -1 0 2 0
(b)
 0  0 1 3 1
(c)
-1 -1  0 3 0
(d)
Compilation time error
(e)
  0 0 1 3 0.
249.
The following program’s output is:
void main() {
int i;
clrscr();
printf( "%d", sizeof int );
}
(a)
2
(b)
4
(c)
Compiler dependent
(d)
Compile time error
(e)
Some Garbage value.
250.
The following program’s output is:
register int i;
void main() {
clrscr();
printf( "%d", i );
}
(a)
0
(b)
Garbage
(c)
Compile time error
(d)
32767
(e)
Runtime error.

Answers





241.
A
According to the definition of pointers.
242.
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
243.
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
244.
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.
245.
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].
246.
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
247.
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'
248.
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
249.
d
The sizeof operator without parenthesis can be applied only to variables but not the datatypes
250.
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



<< Prev 1...  2...  3...  4...  5...  6...  7...  8...  9...  10...  11... 12...  13...  14...  15...  16...  17...  18...  19...  20...  21...  22...  23...  24...  25...  26...  27...  28...  29...  30...  31...  32...  33...  34...  35...  36...  Next >>


No comments :

What you think about these Questions and Answers ? Let me know in comments.

Post a Comment