C Programming and Problem Solving
Questions 161 to 170
161.
|
In ‘C’
which of the following can be used to create the constants for float values
i) Enumerations
ii) const iii)
# define
(a) i
& ii (b) ii only (c) ii & iii (d) i &
iii (e) iii only.
|
162.
|
Choose the
correct output for the following given program.
# include <stdio.h>
void fun(int a, int b, …)
{
int i=0, *p = &b;
for( printf(“ ”);
i<a; i++)
printf(“%d, ”, ++(*p++));
}
void main()
{
fun(1, 0);
fun(3,1,2,3);
}
(a) Syntax
error (b) 1,
2, 3, 4 (c) run time error (d) 0, 1,2,3 (e)
1, 1,2,3.
|
163.
|
For the
following input function scanf(“%d%*d%d”, &x, &y); if the values entered are 900 456
786. Then what will be the values
of integer variables x, y.
(a) 900 456 (b) 456
786 (c) 900
(d) 900
786 (e) Abnormal program termination.
|
164.
|
What is
the output of the following program?
# include
<stdio.h>
void main()
{
int a=5, *pa=&a, b=0, *pb=&b,
**ppa=&pa;
pb=pa;
a += *pb += **ppa;
printf(“ %d, ” “%d, ”
“%d”, *pa, b, **ppa);
}
(a) 20,
0, 20 (b) 20, 20, 20 (c) Syntax Error (d) 0, 20, 0 (e) 0, 20, 20.
|
165.
|
What is
the output of the following program
# include <stdio.h>
struct temp {
int j, i;
}a;
void fun(struct temp *p)
{
printf(“%d, “, *p); p++; printf(“%d”,
*p);
}
void main()
{
struct temp *z = &a;
z->i = 1, z->j = 10;
fun(z);
}
(a) 10,
10 (b) 10, 1 (c) 1, 10 (d) 0, 10 (e) 10, 0.
|
166.
|
What would
be the values assigned to a, b, c if the following statement is extended with
input data item 123456 scanf(“%d %d %d”, &a, &b, &c );
(a) a=12,
b=34, c=56 (b) a=123456 and nothing is assigned to b, c
(c) a=1, b=3, c=5 (d) a, b are not assigned any thing but
c=123456
(e) a=123456, b=0, c=0.
|
167.
|
If the
following loop is implemented then ..
{
static int x;
do {
--x;
printf( “%d”, x++);
}while( x >= 0);
}
(a) The
program will not enter in the loop
(b) There will be a compilation error reported
(c) The loop will run infinitely
(d) A run time error will be reported
(e) It prints 0 once and terminates the do –
while loop successfully.
|
168.
|
The
expression (( fileptr = fopen(“somefile”, “w”)) == NULL ) would be true if
(a) The
file somefile is read only
(b) May be the fileptr is not declared as a
FILE pointer
(c) The file somefile does not exist while
fopen function is being executed
(d) The file somefile could not be created for writing
(e) Both (b) and (c) above.
|
169.
|
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.
|
170.
|
The
getchar() library function
(a) Returns a character when any key is pressed
(b) Returns multiple characters when the keys
are pressed
(c) Returns multiple characters when the keys
are pressed followed by enter key
(d) Both (b) and (c) above
(e) Returns a single character when the keys
are pressed followed by enter key.
|
Answers
161.
|
Answer : (c)
Reason: const, # define can be used to create any constant
of any primitive data type, but Enumerations are only used to create the
integer symbolic constants
|
162.
|
Answer : (b)
Reason: It is same as variable length arguments
list. See any book for variable length arguments list. Be keen at printf
(“%d, ”, ++(*p++));
|
163.
|
Answer : (d)
Reason: Because this form %*format_specifier
suppress the input and do not store it in any variable, and hence 456 is
skipped.
|
164.
|
Answer : (a)
Reason: Because of pointers (*pa=&a, *pb=&b)
and pointer to pointer (**ppa=&pa) and the short form operators (+= )
pb=pa;
a += *pb += **ppa;
printf(“ %d, ” “%d, ” “%d”, *pa, b,
**ppa);
|
165.
|
Answer : (e)
Reason: Because of the set of statements struct temp
*z = &a; z->i = 1, z->j = 10; pointer is pointing to first field
and hence in response to printf(“%d, “, *p); it printed the value of j (see
the order int j, i; in structure
definition temp). And once the pointer is incremented it crosses the current
structure variable (a) and pointing to some other location. So in response to
printf (“%d”, *p); the output was 0.
|
166.
|
Answer : (b)
Reason: Because there is no width specification on
input, hence a single input value 123456 is assigned to first variable i.e.,
a, and b, c are not assigned with any value.
|
167.
|
Answer : (c)
Reason: The loop will run infinitely, because the
statement static int x; causes the value to x be set a 0, and in do – while
(x >= 0), loop we are decrementing (--x) and after again incrementing the
value of x by one in printf (“%d”, x++); so the value of x remains 0 for each
iteration of loop. And hence infinite loop
|
168.
|
Answer : (d)
Reason: Because according to the definition of fopen
() it returns the pointer to the FILE pointer in success and returns NULL in
failure (means could not open the file for writing). Hence it is the most
suitable answer when compared with all the other options given.
|
169.
|
Answer : (a)
Reason: Because FILE is a pre-defined (system
defined) structure of type FILE. Hence the given statement FILE *fptr; only
creates a pointer to the pre-defined structure type FILE, also FILE it
neither a user-defined structure type (FILE) nor a pre-defined data type
(FILE DESCRIPTOR) by definition of itself. Also no file is created without
using fopen ().
|
170.
|
Answer : (e)
Reason: Because the getchar () function reads the
input characters until enter key is pressed, and returns a single character
only ( the first character in the input )
|
thank you.
ReplyDeletec++ tutorial
java tutorial