C Language
Test your C skill in programming language for mca entrance and campus placements by free online preparation and practice paper tests
Questions
Which one of the following is valid for opening a read-only ASCII file?
- fileOpen (filenm, "r")
- fileOpen (filenm, "ra")
- fileOpen (filenm, "read")
- fopen (filenm, "read")
- fopen (filenm, "r")
f = fopen( filename, "r" );
Referring to the code above, what is the proper definition for the variable f?
- FILE f
- FILE *f
- int f
- struct FILE f
- char *f
If there is a need to see output as soon as possible, what function will force the output from the buffer into the output stream?
- flush()
- output()
- fflush()
- dump()
- write()
Short int x; /* assume x is 16 bits in size */, what is the maximum number that can be printed using printf(%d , x), assuming that x is initialized as shown above?
- 127
- 128
- 255
- 32, 767
- 65, 536
Which one of the following can be used to test arrays of primitive quantities for strict equality under Standard C?
- qsort()
- bcmp()
- memcmp()
- strxfrm()
- bsearch()
void crash (void)
{
printf(got here);
*((char *) 0) = 0;
}
The function crash(), defined above, triggers a fault in the memory management hardware for many architectures. Which one of the following explains why got here may not be printed before the crash?
- The C standard says that dereferencing a null pointer causes undefined behavior. This may explain why printf() apparently fails.
- If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs.
- printf() always buffers output until a new line character appears in the buffer. Since no newline was present in the format string, nothing is printed.
- There is insufficient information to determine why the output fails to appear. A broader context is required.
- printf() expects more than a single argument. Since only one argument is given, the crash may actually occur inside printf(), which explains why the string is not printed. puts() should be used instead.
char * dwarves [] =
{
Sleepy,
Dopey Doc,
Happy,
Grumpy Sneezy,
Bashful,
};
How many elements does the array declared above contain? Assume the C compiler employed strictly complies with the requirements of Standard C.
- 4
- 5
- 6
- 7
- 8
char *buffer = 0123456789;
char *ptr = buffer;
ptr += 5;
printf( %s, ptr );
printf( %s, buffer );
What will be printed when the sample code above is executed?
- 0123456789 56789
- 5123456789 5123456789
- 56789 56789
- 0123456789 0123456789
- 56789 0123456789
What number is equivalent to -4e3?
- -4000
- -400
- -40
- 004
- 0004
int debug (const char * fmt, ...) {
extern FILE * logfile;
va_list args;
assert(fmt);
args = va_arg(fmt, va_list);
return vfprintf(logfile, fmt, args);
}
The function debug(), defined above, contains an error. Which one of the following describes it?
- The ellipsis is a throwback from K&R C. In accordance with Standard C, the declaration of args should be moved into the parameter list, and the K&R C macro va_arg() should be deleted from the code.
- vfprintf() does not conform to ISO 9899: 1990, and may not be portable.
- Library routines that accept argument lists cause a fault on receipt of an empty list. The argument list must be validated with va_null() before invoking vfprintf().
- The argument list args has been improperly initialized.
- Variadic functions are discontinued by Standard C; they are legacy constructs from K&R C, and no longer compile under modern compilers.
How does variable definition differ from variable declaration?
- Definition allocates storage for a variable, but declaration only informs the compiler as to the variable's type.
- Declaration allocates storage for a variable, but definition only informs the compiler as to the variable's type.
- Variables may be defined many times, but may be declared only once.
- Variable definition must precede variable declaration.
- There is no difference in C between variable declaration and variable definition.