ANSI C Programming: The Standard Library and Preprocessor

The Standard Library and Preprocessor

What do you associate a file with to allow communication with the file in ANSI C?
A variable
A file
A stream
A pointer

3

Which of the following are standard stdio.h header file
pointers?
EOF
NULL
%010stdin
%010stdout
%010stderr

3, 4, 5
Which of the following methods for reading and writing, using standard I/O, uses the getchar() function?

Reading and writing one character at a time
Reading and writing one string at a time
Formatted I/O
1

Which of the following standard I\O functions are used in reading and writing one string at a time?
%010getchar( )
%010gets( )
%010putchar( )
%010puts( )

2, 4
In which of the following header files is the printf()
function found?
%010stdlib.h
%010stdarg.h
%010stdio.h
%010stddef.h

3
Which of the following printf() statements will produce the output (There are 365 days in a year”?

%010printf("There are %d days in a year.", 365);
%010printf("There are %i days in a year.", 365);
%010printf("There are %X days in a year.", 365);
%010printf("There are % days in a year.", X);

1, 2
Which of the following statements are true about printf() format codes?

The codes d and i interpret variables as decimal
The code o interprets variables as octal
The code u interprets variables as unsigned decimal
The codes x or X interpret variables as hexadecimal
The code X interprets variables as either upper or lower case
|
1, 2, 3, 4
Which of the following formats restricts precision to four places, with no extra whitespaces?
|
Choose an option.
|
4%.0f
0.4f
4%.xf
%.4f
|
4
Which of the following printf() format codes caters for the printing of single-character variables?

%010f
%010e
%010g
%010c
%010s
|
4
When does a call to scanf() return an EOF message?
When it has converted all the variables in a string
When the format string is exhausted
When EOF is entered at stdin
When an error occurs before input conversion
When it reaches a new line character
|
2, 3, 4
Which of the following scanf() format codes read a floating-point number and place it at a pointer of datatype float specified in the argument list?
%010c
%010e
%010f
%010g
%010i
|
2, 3, 4

Which of the following format codes is a literal?
|
Choose an option.
|
[]
[4^]
%
|
3

Which of the following could cause a difference between the input and the output?
|
Choose an option.
|
The size of the input
A mismatch
The format code used
|
2

Identify the fopen() access modes that can be used for writing at the end of a binary file.
|
Choose more than one item.
|
%010w+b
%010ab
%010w+
%010w
%010a
%010a+b
|
1, 2, 6
|
30
|
Correct.
|
5
|
Partly right. The correct options are highlighted.
|
You have not made any correct choices. The correct options are highlighted.

@@QUES 020102t SXY Q,0,0,350,327
What is equivalent to the getchar() function?
|
Choose an option.
|
%010putc(stdin)
%010getc(stdout)
%010putc(stdout)
%010getc(stdin)
|
4
Identify the true statements about the fgets() function.
|
Choose more than one item.
|
It reads the new line character
The character pointer returned points to the file being read
If there's no new line character, it reads the maximum number of characters
It returns a NULL if there's an error
It has two arguments
|
1, 3, 4
Which is an equivalent to the putchar() function?
|
Choose an option.
|
%010getc(stdin)
%010putc(c, stdout)
%010getc(stdout)
%010putc(c, stdin)
|
2
If an fopen() operation is successful, which pointer to that file is returned?
|
Choose an option.
|
Null pointer
File pointer
Pointer
|
2
|
Identify the true statements about fully buffered I/O.

|
A buffer of data is read from or written to the standard I/O buffer
It reads data one character at a time from the normal file I/O buffer
Both fgets() and fputs() are fully buffered I/O functions
BUFSIZ is defined in stdio.h
A buffer of data is described by a data object, such as a structure
|
1, 4, 5
Identify the true statements about the fread() function.
|
Choose more than one item.
|
It has three arguments
Its return value is the number of objects successfully read
Its first argument is a pointer to a region of memory to receive the data
The last argument must be of datatype int
The ferror() and feof() functions should be used with fread() to check for problems
|
2, 3, 5
Identify which of the following positions is equivalent to SEEK_SET used as the origin argument in the fseek() function?
|
Choose an option.
|
The current position
The start of the file
The end of the file
|
2
It clears the buffer if the file pointed to by fp is an input file
It writes unwritten data if the file pointed to by fp is an output file
It returns EOF if a write error occurs
It returns a nonzero value if no write error occurs
If fp is a null pointer, there is no flushing action
|
1, 2, 3
What is the correct definition of the strncat() function?
|
Choose an option.
|
It appends a maximum of n characters from a second string to the end of the first string
It copies a maximum of n characters from a second string to the first string
It appends a whole second string to the end of the first string
It breaks the first string into a sequence of tokens, using a second string as a delimiter
|
1
Identify what is returned by the strpbrk() function if string matching occurs.
|
Choose an option.
|
A null pointer
A pointer to the first occurrence in the first string of any character in the second string
The length of the field spanned in the first string
A pointer to the first occurrence of one particular character in a string
|
2
|
20
|
Correct.
|
Incorrect. The correct option is highlighted.

@@QUES 020403t SXY Q,0,0,362,363
A character string s1 is initialized to "Thomas Jefferson". Identify the value of num returned by the following statement:

num = strspn(s1, "JsmoTha ");
|
Choose an option.
|
2
4
6
8
10
|
4
Which of the following functions returns a pointer to the last occurrence of a character in a string?
|
Choose an option.
|
%010strchr()
%010strncat()
%010strncpy()
%010strpbrk()
%010strrchr()
%010strspn()
|
5
Where are the command-line arguments argc and argv declared?
|
Choose an option.
|
In the stdio.h header file
In the header of the main() function
In the body of the main() function
After the main() function
|
2

What is the minimum value for the parameter argc?
|
Choose an option.
|
0
1
2
3
|
2
Of which type of pointers is the parameter argv an array?
|
Choose an option.
|
String
Argument
Character
Structure
|
3
When is the actual length of the command-line argument argv established?
|
Choose an option.
|
At preprocessing time
At compilation time
At linking time
At run time
|
4
Which of the following arguments accesses the object referenced by the first pointer in the argv array?
|
Choose an option.
|
*argv
**argv
+argv
++argv
|
1
Identify the features of the following statement:

#include
|
Choose more than one item.
|
It includes the source code for header.h in the program
It causes the preprocessor to search the standard library directory for header.h
It causes the preprocessor to search the user directories for header.h
It can be nested in another header file
It can be included at any stage of the program
|
1, 2, 4, 5
Which of the following are features of ANSI C preprocessor macros?
|
Choose more than one item.
|
They use less memory than functions
They execute faster than functions
The call to a macro is replaced with the definition's source code each time
They can include a function call
They can take arguments
|
2, 3, 4, 5

Identify the correct option, given this definition:

#define ONE 1
#define TWO ONE+ONE
|
Choose an option.
|
TWO*TWO=1
TWO*TWO=2
TWO*TWO=3
TWO*TWO=4
|
3

How does the preprocessor interpret the code  #define MIN (a,b)?
|
Choose an option.
|
As a macro that takes a and b as formal parameters
As a macro that takes a and b as actual parameters
As a macro where MIN has the value of a or b
As a macro with MIN as the identifier and (a,b) as the token sequence
|
4

Why could the following call to the MIN macro – MIN(*ptr++, 14); – cause a problem in the source code?
|
Choose an option.
|
It uses pointer notation
The preprocessor will interpret the terms in parentheses as a token sequence
The value of ptr will change each time it is used
Pointers and integers cannot be combined as actual parameters in a macro call
|
3
|
Which of the following is the alternative branch for #ifdef?
|
Choose an option.
|
#ifndef
#elif
#if
#else
|
4

Under what circumstances will an #ifndef statement execute?
Only when the associated macro has been previously defined
Only when the associated macro has not been previously defined
Whether or not the associated macro has been previously defined
When all other statements have been executed
|
2
What does the following statement do?

#undef MIN

It tests to see if the macro MIN has been previously defined
It causes the preprocessor to disregard the definition of MIN
It executes only if MIN is previously undefined
It accepts any value for MIN other than the defined value
|
2
Which of the following are features of __FILE__?
It is a standard preprocessor macro
It is a pointer to a string containing the name of the source file
It is used in conjunction with diagnostic tools for displaying error messages
It is generated using the #line directive
It can be changed to point to a different string

1, 2, 3

Identify the true statements about standard preprocessor macros.
The macro __LINE__ stores a value corresponding to a line number in the source code
The value for the __LINE__ macro is set using the #line directive
The value for the __DATE__ macro is set using the #date directive
The __TIME__ macro is the time of translation expressed as a string
The __STDC__ macro is the name of the source file expressed as a string
|
1, 2, 4
What is the function of the preprocessor directive #error?
It automatically includes a header file of standard error messages
It causes an error to occur when the preprocessor reaches an undefined macro
It causes the compiler to stop
It allows implementation-defined error messages to be given to the compiler
|
3

Comments

Popular Posts