C Programming and Problem Solving Questions and Answers 51 to 60

C Programming and Problem Solving

Questions 51 to 60



51.
What is printed when this program is executed
int f( int x)  {
if ( x<= 4)
return x;
return f(--x);
}
void main()     {
printf ("%d\n", f(7));
}
(a)
4
(b)
4 5 6 7
(c)
1 2 3 4
(d)
Syntax error
(e)
Runtime error.
52.
Find the output for the following C program
Y=10;
if( Y++>9 && Y++!=10 && Y++>10)
printf("%d", Y);
else
printf("%d", Y);
(a)
Syntax error
(b)
Runtime error
(c)
10
(d)
13
(e)
12.
53.
What are the values of a, b are if the following code fragment is executed
int a ,b=7;
a=b<4?b<<1:b>4?7>>1:a;
(a)
Garbage and 7
(b)
7 and 3
(c)
3 and 7
(d)
3 and 3
(e)
7 and 7.
54.
Find the output of the following program:
#define INC(X) X++
void main()
{
int X=4;
printf("%d",INC(X++));
}
(a)
4
(b)
5
(c)
6
(d)
Syntax error
(e)
Runtime error.
55.
The given statement  FILE *fptr;
(a)
Defines a pointer to the pre-defined structure type FILE
(b)
Defines a pointer to the user-defined structure type FILE
(c)
Defines a pointer to the pre-defined data type FILE DESCRIPTOR
(d)
Creates a file with the name fptr
(e)
Creates a file pointed by fptr.
56.
Consider the following code
struct account {
int acno;
}svar, *pv = &svar;
then the acno can be accessed by
(a)
svar.acno             
(b)
pv->acno             
(c)
(*pv).acno
(d)
a & b & c
(e)
a & b only.
57.
Pick the equivalent control structure for the following repetitive control structure
for( C1; C3; C2 ) { statements; }
(a)
while( C1) { C2; statements; C3; }
(b)
C1; while(C2) { statements; C3; }
(c)
while( C3) { C1; statements; C2; }
(d)
C1; while(C3) { statements; C2; }
(e)
C1; C3; while(C2) { statements; }.
58.
What is the correct output of the following program?
# include <string.h>
void main()
{
char str[] = ”C EXAMINATION”, rev[17];
int i = strlen(str), j=0;
for( ; i>=0; rev[j++] = str[i--]);
rev[j] = ‘\0’;
puts(rev);
}
(a)
C    
(b)
Syntax error 
(c)
NOITANIMAXE C       
(d)
NOITANIMAXE
(e)
No output at all.
59.
Choose the correct output for the following program
# include <stdio.h>
void main(){
int a=10, b=11, c=13,   d;
d = (a=c, b+=a, c=a+b+c);
printf(“ %d, %d”,  d, a);
}
(a)
50, 13       
(b)
50, 34    
(c)
Garbage value      
(d)
R value required   
(e)
Syntax error.
60.
In ‘C’ which of the following can be used to create the constants for float values?
I.     Enumerations
II.     const
III.    # define
(a)
Both (I) and (II) above
(b)
Only (II) above
(c)
Both (I) and (III) above
(d)
Both (II) and (III) above
(e)
Only (III) above.

Answers


51.
A
In this recursive function call the function return to main caller when the value of x is 4. Hence the output
52.
D
What so ever the outcome of the expression is Y is post incremented three times.
53.
C
7>>1 shifts 7 towards left by 1 position and hence 3 will be assigned to a. variable b remains same.
54.
D
L valve required for this expression INC(X++++) which is illegal.
55.
A
FILE is a pre-defined structure.
56.
D
As all the ways are legal and valid.
57.
D
C1, C3, C2 are place holders for initialization part, condition part and the increment/decrement part. Hence both options for for loop and while loop are same.
58.
E
As i is with the length of string and hence in array rev the contents are copied as “\0 NOITANIMAXE C”. But while displaying those contents with puts function it stops because of the first character ‘\0’ and hence no output.
59.
A
for any comma separated expression the out come is the right most part.
60.
D
As Enumerations can’t be used to create the float constants.


<< 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 >>


2 comments :