Date Редакция Категория comp Теги C

Оригинальный текст содержал довольно много пропусков и ашипок. Не исключено, что последние еще остались.

Правильный ответ (ANSWER) можно узнать, выделив список вариантов мышкой. Комментарии к ответам.

1.

int z,x=5,y=-10,a=4,b=2; 
z = x++ - --y * b / a;

What number will z in the sample code above contain?

  • 5
  • 6
  • 10 ANSWER
  • 11
  • 12

2.

With every use of a memory allocation function, what function should be used to release allocated memory which is no longer needed?

  • unalloc()
  • dropmem()
  • dealloc()
  • release()
  • free() ANSWER

3.

Code:

void *ptr;
myStruct myArray[10];
ptr = myArray;

Which of the following is the correct way to increment the variable "ptr"?

  • ptr = ptr + sizeof(myStruct); ANSWER
  • ++(int*)ptr;
  • ptr = ptr + sizeof(myArray);
  • increment(ptr);
  • ptr = ptr + sizeof(ptr);

4.

Code:

char* myFunc (char *ptr)
{
 ptr += 3;
 return (ptr);
} 
int main()
{
 char *x, *y;
 x = "HELLO";
 y = myFunc (x);
 printf ("y = %s \n", y);
 return 0;
}

What will print when the sample code above is executed?

  • y = HELLO
  • y = ELLO
  • y = LLO
  • y = LO ANSWER
  • x = O

5.

Code:

struct node *nPtr, *sPtr;    /* pointers for a linked list. */ 
for (nPtr=sPtr; nPtr; nPtr=nPtr->next)
{    
 free(nPtr);
}

The sample code above releases memory from a linked list. Which of the choices below accurately describes how it will work?

  • It will work correctly since the for loop covers the entire list.
  • It may fail since each node "nPtr" is freed before its next address can be accessed. ANSWER
  • In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next".
  • This is invalid syntax for freeing memory.
  • The loop will never end.

6.

What function will read a specified number of elements from a file?

  • fileread()
  • getline()
  • readfile()
  • fread() ANSWER
  • gets()

7.

"My salary was increased by 15%!"

Select the statement which will EXACTLY reproduce the line of text above.

  • printf("\"My salary was increased by 15/%\!\"\n");
  • printf("My salary was increased by 15%!\n");
  • printf("My salary was increased by 15'%'!\n");
  • printf("\"My salary was increased by 15%%!\"\n"); ANSWER
  • printf("\"My salary was increased by 15'%'!\"\n");

8.

What is a difference between a declaration and a definition of a variable?

  • Both can occur multiple times, but a declaration must occur first.
  • There is no difference between them.
  • A definition occurs once, but a declaration may occur many times. ANSWER
  • A declaration occurs once, but a definition may occur many times.
  • Both can occur multiple times, but a definition must occur first.

9.

int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

What value does testarray[2][1][0] in the sample code above contain?

  • 3
  • 5
  • 7
  • 9
  • 11 ANSWER

10.

int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);

What will be the output when following code is executed

  • 12,10,11,13
  • 22,10,11,13
  • 22,11,11,11
  • 12,11,11,11
  • 22,13,13,13 ANSWER. Хотя в соответствии со стандартом будет "Undefined behavior"..

11.

int x[] = { 1, 4, 8, 5, 1, 4 }; 
int *ptr, y; 
ptr  = x + 4; 
y = ptr - x;

What does y in the sample code above equal?

  • -3
  • 0
  • 4 ANSWER
  • 4 + sizeof(int)
  • 4 * sizeof(int)

12.

void myFunc (int x) 
{ 
   if (x > 0)
   myFunc(--x); 
   printf("%d, ", x); 
}

int main() 
{ 
   myFunc(5); 
   return 0; 
}

What will the above sample code produce when executed?

  • 1, 2, 3, 4, 5, 5,
  • 4, 3, 2, 1, 0, 0,
  • 5, 4, 3, 2, 1, 0,
  • 0, 0, 1, 2, 3, 4, ANSWER
  • 0, 1, 2, 3, 4, 5,

13.

`11 ^ 5`

What does the operation shown above produce?

  • 1
  • 6
  • 8
  • 14 ANSWER
  • 15

14.

#define MAX_NUM 15

Referring to the sample above, what is MAX_NUM?

  • MAX_NUM is an integer variable.
  • MAX_NUM is a linker constant.
  • MAX_NUM is a precompiler constant.
  • MAX_NUM is a preprocessor macro. ANSWER
  • MAX_NUM is an integer constant.

15.

Which one of the following will turn off buffering for stdout?

  • setbuf( stdout, FALSE );
  • setvbuf( stdout, NULL );
  • setbuf( stdout, NULL ); ANSWER
  • setvbuf( stdout, _IONBF );
  • setbuf( stdout, _IONBF );

16.

What is a proper method of opening a file for writing as binary file?

  • FILE *f = fwrite( "test.bin", "b" );
  • FILE *f = fopenb( "test.bin", "w" );
  • FILE *f = fopen( "test.bin", "wb" ); ANSWER
  • FILE *f = fwriteb( "test.bin" );
  • FILE *f = fopen( "test.bin", "bw" );

17.

Which one of the following functions is the correct choice for moving blocks of binary data that are of arbitrary size and position in memory?

  • memcpy()
  • memset()
  • strncpy()
  • strcpy()
  • memmove() ANSWER

18.

int x = 2 * 3 + 4 * 5;

What value will x contain in the sample code above?

  • 22
  • 26 ANSWER
  • 46
  • 50
  • 70

19.

void * array_dup (a, number, size) 
  const void * a; 
  size_t number; 
  size_t size; 
{ 
  void * clone; 
  size_t bytes; 
  assert(a != NULL); 
  bytes = number * size; 
  clone = alloca(bytes); 
  if (!clone) 
    return clone; 
  memcpy(clone, a, bytes); 
  return clone; 
}

The function array_dup(), defined above, contains an error. Which one of the following correctly analyzes it?

  • If the arguments to memcpy() refer to overlapping regions, the destination buffer will be subject to memory corruption.
  • array_dup() declares its first parameter to be a pointer, when the actual argument will be an array.
  • size_t is not a Standard C defined type, and may not be known to the compiler.
  • The definition of array_dup() is unusual. Functions cannot be defined using this syntax.
  • The memory obtained from alloca() is not valid in the context of the caller. Moreover, alloca() is nonstandard. ANSWER. Комментарий

20.

int var1;

If a variable has been declared with file scope, as above, can it safely be accessed globally from another file?

  • Yes; it can be referenced through the register specifier.
  • No; it would have to have been initially declared as a static variable.
  • No; it would need to have been initially declared using the global keyword.
  • Yes; it can be referenced through the publish specifier.
  • Yes; it can be referenced through the extern specifier. ANSWER

21.

time_t t;

Which one of the following statements will properly initialize the variable t with the current time from the sample above?

22.

Which one of the following provides conceptual support for function calls?

  • The system stack ANSWER
  • The data segment
  • The processor's registers
  • The text segment
  • The heap

23.

C is which kind of language?

  • Machine
  • Procedural ANSWER
  • Assembly
  • Object-oriented
  • Strictly-typed

24.

int i,j; 
int ctr = 0; 
int myArray[2][3]; 
for (i=0; i<3; i++) 
   for (j=0; j<2; j++) 
   { 
      myArray[j][i] = ctr; 
      ++ctr; 
   }

What is the value of myArray[1][2]; in the sample code above?

  • 1
  • 2
  • 3
  • 4
  • 5 ANSWER

25.

int x = 0; 
for (x=1; x<4; x++); 
printf("x=%d\n", x);

What will be printed when the sample code above is executed?

  • x=0
  • x=1
  • x=3
  • x=4 ANSWER
  • x=5

26.

int x = 3; 
if( x == 2 );
  x = 0; 
if( x == 3 )
  x++; 
else x += 2;

What value will x contain when the sample code above is executed?

  • 1
  • 2 ANSWER
  • 3
  • 4
  • 5

27.

char *ptr; 
char myString[] = "abcdefg"; 
ptr = myString; 
ptr += 5;

What string does ptr point to in the sample code above?

  • fg ANSWER
  • efg
  • defg
  • cdefg
  • None of the above

28.

double x = -3.5, y = 3.5; 
printf( "%.0f : %.0f\n", ceil( x ), ceil( y ) ); 
printf( "%.0f : %.0f\n", floor( x ), floor( y ) );

What will the code above print when executed?

  • ANSWER
-3 : 4
-4 : 3
-4 : 4
-3 : 3
-4 : 3
-4 : 3
-4 : 3
-3 : 4
-3 : 3
-4 : 4

29.

Which one of the following will declare a pointer to an integer at address 0x200 in memory?

*

int *x;
*x = 0x200;
  • int *x = &0x200;
  • int *x = *0x200;
  • int *x = 0x200; ANSWER
  • int *x( &0x200 );

30.

int x = 5; 
int y = 2; 
char op = '*'; 
switch (op) 
{ 
  default : x += 1; 
  case '+' : x += y; /*It will go to all the cases*/
  case '-' : x -= y; 
}

After the sample code above has been executed, what value will the variable x contain?

  • 4
  • 5
  • 6 ANSWER
  • 7
  • 8

31.

x = 3, counter = 0; 
while ((x-1)) 
{ 
   ++counter; 
   x--; 
}

Referring to the sample code above, what value will the variable counter have when completed?

  • 0
  • 1
  • 2 ANSWER
  • 3
  • 4

32.

char ** array [12][12][12];

Consider array, defined above. Which one of the following definitions and initializations of p is valid?

  • char ** (* p) [12][12] = array; ANSWER
  • char ***** p = array;
  • char * (* p) [12][12][12] = array;
  • const char ** p [12][12][12] = array;
  • char (** p) [12][12] = array;

33.

void (*signal(int sig, void (*handler) (int))) (int);

Which one of the following definitions of sighandler_t allows the above declaration to be rewritten as follows:

sighandler_t signal (int sig, sighandler_t handler);
  • typedef void (*sighandler_t) (int); ANSWER
  • typedef sighandler_t void (*) (int);
  • typedef void *sighandler_t (int);
  • #define sighandler_t(x) void (*x) (int)
  • #define sighandler_t void (*) (int)

34.

All of the following choices represent syntactically correct function definitions. Which one of the following represents a semantically legal function definition in Standard C?

int count_digits (const char * buf) { 
  assert(buf != NULL); 
  int cnt = 0, i; 
  for (i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  return cnt; 
}
int count_digits (const char * buf) { 
  int cnt = 0; 
  assert(buf != NULL); 
  for (int i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  return cnt; 
}
int count_digits (const char * buf) { 
  int cnt = 0, i; 
  assert(buf != NULL); 
  for (i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  return cnt; 
}
int count_digits (const char * buf) { 
  assert(buf != NULL); 
  for (i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  return cnt; 
}
int count_digits (const char * buf) { 
  assert(buf != NULL); 
  int cnt = 0; 
  for (int i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  return cnt; 
}

35.

struct customer *ptr = malloc( sizeof( struct customer ) );

Given the sample allocation for the pointer ptr found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?

  • ptr = realloc( ptr, 10 * sizeof( struct customer)); ANSWER
  • realloc( ptr, 9 * sizeof( struct customer ) );
  • ptr += malloc( 9 * sizeof( struct customer ) );
  • ptr = realloc( ptr, 9 * sizeof( struct customer ) );
  • realloc( ptr, 10 * sizeof( struct customer ) );

36.

Which one of the following is a true statement about pointers?

  • Pointer arithmetic is permitted on pointers of any type.
  • A pointer of type void * can be used to directly examine or modify an object of any type.
  • Standard C mandates a minimum of four levels of indirection accessible through a pointer.
  • A C program knows the types of its pointers and indirectly referenced data items at runtime.
  • Pointers may be used to simulate call-by-reference. ANSWER

37.

Which one of the following functions returns the string representation from a pointer to a time_t value?

  • localtime
  • gmtime
  • strtime
  • asctime
  • ctime ANSWER

38.

short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} }; 
printf( "%d\n", sizeof( testarray ) );

Assuming a short is two bytes long, what will be printed by the above code?

  • It will not compile because not enough initializers are given.
  • 6
  • 7
  • 12
  • 24 ANSWER

39.

char buf [] = "Hello world!";
char * buf = "Hello world!";

In terms of code generation, how do the two definitions of buf, both presented above, differ?

  • The first definition certainly allows the contents of buf to be safely modified at runtime; the second definition does not. ANSWER
  • The first definition is not suitable for usage as an argument to a function call; the second definition is.
  • The first definition is not legal because it does not indicate the size of the array to be allocated; the second definition is legal.
  • They do not differ -- they are functionally equivalent.
  • The first definition does not allocate enough space for a terminating NUL-character, nor does it append one; the second definition does.

40.

In C Programming, How to represent a logical AND?

  • @
  • ||
  • .AND.
  • && ANSWER
  • .AND

41.

How do printf()'s format specifiers %e and %f differ in their treatment of floating-point numbers?

  • %e always displays an argument of type double in engineering notation; %f always displays an argument of type double in decimal notation. ANSWER
  • %e expects a corresponding argument of type double; %f expects a corresponding argument of type float.
  • %e displays a double in engineering notation if the number is very small or very large. Otherwise, it behaves like %f and displays the number in decimal notation.
  • %e displays an argument of type double with trailing zeros; %f never displays trailing zeros.
  • %e and %f both expect a corresponding argument of type double and format it identically. %e is left over from K&R C; Standard C prefers %f for new code.

42.

Which one of the following Standard C functions can be used to reset end-of-file and error conditions on an open stream?

  • clearerr() ANSWER
  • fseek()
  • ferror()
  • feof()
  • setvbuf()

43.

Which one of the following will read a character from the keyboard and will store it in the variable c?

  • c = getc();
  • getc( &c );
  • c = getchar( stdin );
  • getchar( &c )
  • c = getchar(); ANSWER

44.

#include <stdio.h> 

int i; 

void increment( int i ) 
{ 
   i++; 
} 

int main() 
{ 
   for( i = 0; i < 10; increment( i ) ) 
   { 
   } 
   printf("i=%d\n", i); 
   return 0; 
}

What will happen when the program above is compiled and executed?

  • It will not compile.
  • It will print out: i=9.
  • It will print out: i=10.
  • It will print out: i=11.
  • It will loop indefinitely. ANSWER

45.

char ptr1[] = "Hello World"; 
char *ptr2 = malloc( 5 ); 
ptr2 = ptr1;

What is wrong with the above code (assuming the call to malloc does not fail)?

  • There will be a memory overwrite.
  • There will be a memory leak. ANSWER
  • There will be a segmentation fault.
  • Not enough space is allocated by the malloc.
  • It will not compile.

46.

int i = 4; 
switch (i) 
{ 
   default: 
      ; 
   case 3: 
      i += 5; 
      if ( i == 8) 
      { 
         i++; 
         if (i == 9) break; 
         i *= 2; 
      } 
      i -= 4; 
      break; 
   case 8: 
      i += 5; 
      break;
} 
printf("i = %d\n", i);

What will the output of the sample code above be?

  • i = 5 ANSWER
  • i = 8
  • i = 9
  • i = 10
  • i = 18

47.

Which one of the following C operators is right associative?

  • = ANSWER
  • ,
  • []
  • ^
  • ->

48.

What does the auto specifier do?

  • It automatically initializes a variable to 0;.
  • It indicates that a variable's memory will automatically be preserved. ANSWER
  • It automatically increments the variable when used.
  • It automatically initializes a variable to NULL.
  • It indicates that a variable's memory space is allocated upon entry into the block.

49.

How do you include a system header file called sysheader.h in a C source file?

  • #include <sysheader.h> ANSWER
  • #incl "sysheader.h"
  • #includefile <sysheader>
  • #include sysheader.h
  • #incl <sysheader.h>

50.

Which one of the following printf() format specifiers indicates to print a double value in decimal notation, left aligned in a 30-character field, to four (4) digits of precision?

  • %-30.4e
  • %4.30e
  • %-4.30f
  • %-30.4f ANSWER
  • %#30.4f

51.

int x = 0; 
for ( ; ; ) 
{ 
    if (x++ == 4)
        break; 
    continue; 
} 
printf("x=%d\n", x);

What will be printed when the sample code above is executed?

  • x=0
  • x=1
  • x=4
  • x=5 ANSWER
  • x=6

52.

According to the Standard C specification, what are the respective minimum sizes (in bytes) of the following three data types: short; int; and long?

  • 1, 2, 2
  • 1, 2, 4
  • 1, 2, 8
  • 2, 2, 4 ANSWER
  • 2, 4, 8

53.

int y[4] = {6, 7, 8, 9}; 
int *ptr = y + 2; 
printf("%d\n", ptr[ 1 ] );  /*ptr+1 == ptr[1]*/

What is printed when the sample code above is executed?

  • 6
  • 7
  • 8
  • 9 ANSWER
  • The code will not compile.

54.

penny = one nickel = five dime = ten quarter = twenty-five How is enum used to define the values of the American coins listed above?

  • enum coin {(penny,1), (nickel,5), (dime,10), (quarter,25)};
  • enum coin ({penny,1}, {nickel,5}, {dime,10}, {quarter,25});
  • enum coin {penny=1,nickel=5,dime=10,quarter=25}; ANSWER
  • enum coin (penny=1,nickel=5,dime=10,quarter=25);
  • enum coin {penny, nickel, dime, quarter} (1, 5, 10, 25);

55.

char txt [20] = "Hello world!\0";

How many bytes are allocated by the definition above?

  • 11 bytes
  • 12 bytes
  • 13 bytes
  • 20 bytes ANSWER
  • 21 bytes

56.

int i = 4; 
int x = 6; 
double z; 
z =  x / i; 
printf("z=%.2f\n", z);

What will print when the sample code above is executed?

  • z=0.00
  • z=1.00 ANSWER
  • z=1.50
  • z=2.00
  • z=NULL

57.

Which one of the following variable names is NOT valid?

  • go_cart
  • go4it
  • 4season ANSWER
  • run4
  • _what

58.

int a [8] = { 0, 1, 2, 3 };

The definition of a above explicitly initializes its first four elements. Which one of the following describes how the compiler treats the remaining four elements?

  • Standard C defines this particular behavior as implementation-dependent. The compiler writer has the freedom to decide how the remaining elements will be handled.
  • The remaining elements are initialized to zero (0). ANSWER
  • It is illegal to initialize only a portion of the array. Either the entire array must be initialized, or no part of it may be initialized.
  • As with an enum, the compiler assigns values to the remaining elements by counting up from the last explicitly initialized element. The final four elements will acquire the values 4, 5, 6, and 7, respectively.
  • They are left in an uninitialized state; their values cannot be relied upon.

59.

Which one of the following is a true statement about pointers?

  • They are always 32-bit values.
  • For efficiency, pointer values are always stored in machine registers.
  • With the exception of generic pointers, similarly typed pointers may be subtracted from each other. ANSWER
  • A pointer to one type may not be cast to a pointer to any other type.
  • With the exception of generic pointers, similarly typed pointers may be added to each other.

60.

Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?

  • int *ptr = (int *) malloc(10, sizeof(int));
  • int *ptr = (int *) calloc(10, sizeof(int)); ANSWER
  • int *ptr = (int *) malloc(10*sizeof(int));
  • int *ptr = (int *) alloc(10*sizeof(int));
  • int *ptr = (int *) calloc(10*sizeof(int));

61.

What are two predefined FILE pointers in C?

  • stdout and stderr ANSWER
  • console and error
  • stdout and stdio
  • stdio and stderr
  • errout and conout

62.

u32 X (f32 f)
{ 
    union { 
        f32 f; 
        u32 n; 
    } u; 
    u.f = f; 
    return u.n; 
}

Given the function X(), defined above, assume that u32 is a type-definition indicative of a 32-bit unsigned integer and that f32 is a type-definition indicative of a 32-bit floating-point number. Which one of the following describes the purpose of the function defined above?

  • X() effectively rounds f to the nearest integer value, which it returns.
  • X() effectively performs a standard typecast and converts f to a roughly equivalent integer.
  • X() preserves the bit-pattern of f, which it returns as an unsigned integer of equal size. ANSWER
  • Since u.n is never initialized, X() returns an undefined value. This function is therefore a primitive pseudorandom number generator.
  • Since u.n is automatically initialized to zero (0) by the compiler, X() is an obtuse way of always obtaining a zero (0) value.

63.

long factorial (long x) 
{ 
   ???? 
   return x * factorial(x - 1); 
}

With what do you replace the ???? to make the function shown above return the correct answer?

  • if (x == 0) return 0;
  • return 1;
  • if (x >= 2) return 2;
  • if (x == 0) return 1;
  • if (x <= 1) return 1; ANSWER

64.

/* Increment each integer in the array 'p' of * size 'n'. */
void increment_ints (int p [/*n*/], int n)
{
    assert(p != NULL); /* Ensure that 'p' isn't a null pointer. */
    assert(n >= 0);    /* Ensure that 'n' is nonnegative. */
    while (n)          /* Loop over 'n' elements of 'p'. */
    {
        *p++;          /* Increment *p. */
        p++, n--;      /* Increment p, decrement n. */
    }
}

Consider the function increment_ints(), defined above. Despite its significant inline commentary, it contains an error. Which one of the following correctly assesses it?

  • *p++ causes p to be incremented before the dereference is performed, because both operators have equal precedence and are right associative.
  • An array is a nonmodifiable lvalue, so p cannot be incremented directly. A navigation pointer should be used in conjunction with p.
  • *p++ causes p to be incremented before the dereference is performed, because the autoincrement operator has higher precedence than the indirection operator. ANSWER
  • The condition of a while loop must be a Boolean expression. The condition should be n != 0.
  • An array cannot be initialized to a variable size. The subscript n should be removed from the definition of the parameter p.

65.

How is a variable accessed from another file?

  • The global variable is referenced via the extern specifier. ANSWER
  • The global variable is referenced via the auto specifier.
  • The global variable is referenced via the global specifier.
  • The global variable is referenced via the pointer specifier.
  • The global variable is referenced via the ext specifier.

66.

When applied to a variable, what does the unary "&" operator yield?

  • The variable's value.
  • The variable's binary form.
  • The variable's address. ANSWER
  • The variable's format.
  • The variable's right value.

67.

/* sys/cdef.h */ 
#if     defined(__STDC__) || defined(__cplusplus) 
#define __P(protos)   protos 
#else 
#define __P(protos)   () 
#endif 
/* stdio.h */ 
#include <sys/cdefs.h> 
div_t div __P((int, int));

The code above comes from header files for the FreeBSD implementation of the C library. What is the primary purpose of the __P() macro?

  • The __P() macro has no function, and merely obfuscates library function declarations. It should be removed from further releases of the C library.
  • The __P() macro provides forward compatibility for C++ compilers, which do not recognize Standard C prototypes.
  • Identifiers that begin with two underscores are reserved for C library implementations. It is impossible to determine the purpose of the macro from the context given.
  • The __P() macro provides backward compatibility for K&R C compilers, which do not recognize Standard C prototypes. ANSWER
  • The __P() macro serves primarily to differentiate library functions from application-specific functions.

68.

Which one of the following is NOT a valid identifier?

  • __ident
  • auto ANSWER
  • bigNumber
  • g42277
  • peaceful_in_space

69.

/* Read an arbitrarily long string. */
int read_long_string (const char ** const buf) { 
  char * p = NULL; 
  const char * fwd = NULL; 
  size_t len = 0; 
  assert(buf); 
  do
  { 
   p = realloc(p, len += 256); 
   if (!p) 
    return 0; 
   if (!fwd) 
    fwd = p; 
   else 
    fwd = strchr(p, '\0'); 
  } while (fgets(fwd, 256, stdin)); 
  *buf = p; 
  return 1; 
}

The function read_long_string(), defined above, contains an error that may be particularly visible under heavy stress. Which one of the following describes it?

  • The write to *buf is blocked by the const qualifications applied to its type.
  • If the null pointer for char is not zero-valued on the host machine, the implicit comparisons to zero (0) may introduce undesired behavior. Moreover, even if successful, it introduces machine-dependent behavior and harms portability.
  • The symbol stdin may not be defined on some ANCI C compliant systems.
  • The else causes fwd to contain an errant address.
  • If the call to realloc() fails during any iteration but the first, all memory previously allocated by the loop is leaked. ANSWER

70.

FILE *f = fopen( fileName, "r" ); 
readData( f ); 
if( ???? ) 
{ 
  puts( "End of file was reached" ); 
}

Which one of the following can replace the ???? in the code above to determine if the end of a file has been reached?

  • f == EOF
  • feof( f ) ANSWER
  • eof( f )
  • f == NULL
  • !f

71.

Global variables that are declared static are ______. Which one of the following correctly completes the sentence above?

  • Deprecated by Standard C
  • Internal to the current translation unit ANSWER
  • Visible to all translation units
  • Read-only subsequent to initialization
  • Allocated on the heap

72.

/* Read a double value from fp. */
double read_double (FILE * fp) { 
  double d; 
  assert(fp != NULL); 
  fscanf(fp, " %lf", d); 
  return d; 
}

The code above contains a common error. Which one of the following describes it?

  • fscanf() will fail to match floating-point numbers not preceded by whitespace.
  • The format specifier %lf indicates that the corresponding argument should be long double rather than double.
  • The call to fscanf() requires a pointer as its last argument. ANSWER
  • The format specifier %lf is recognized by fprintf() but not by fscanf().
  • d must be initialized prior to usage.

73.

Which one of the following is NOT a valid C identifier?

  • ___S
  • 1___ ANSWER
  • ___1
  • ___
  • S___

74.

According to Standard C, what is the type of an unsuffixed floating-point literal, such as 123.45?

  • long double
  • Unspecified
  • float
  • double ANSWER
  • signed float

75.

Which one of the following is true for identifiers that begin with an underscore?

  • They are generally treated differently by preprocessors and compilers from other identifiers.
  • They are case-insensitive.
  • They are reserved for usage by standards committees, system implementers, and compiler engineers. ANSWER
  • Applications programmers are encouraged to employ them in their own code in order to mark certain symbols for internal usage.
  • They are deprecated by Standard C and are permitted only for backward compatibility with older C libraries.

76.

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"); ANSWER

77.

f = fopen( filename, "r" );

Referring to the code above, what is the proper definition for the variable f?

  • FILE f;
  • FILE *f; ANSWER
  • int f;
  • struct FILE f;
  • char *f;

78.

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() ANSWER
  • dump()
  • write()

79.

short int x; /* assume x is 16 bits in size */

What is the maximum number that can be printed using printf("%d\n", x), assuming that x is initialized as shown above?

  • 127
  • 128
  • 255
  • 32,767 ANSWER
  • 65,536

80.

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. ANSWER Комментарий
  • printf() always buffers output until a newline 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.

81.

char * dwarves [] = { 
  "Sleepy", 
  "Dopey" "Doc", 
  "Happy", 
  "Grumpy" "Sneezy", 
  "Bashful", 
};

How many elements does the array dwarves (declared above) contain? Assume the C compiler employed strictly complies with the requirements of Standard C.

  • 4
  • 5 ANSWER
  • 6
  • 7
  • 8

82.

Which one of the following can be used to test arrays of primitive quantities for strict equality under Standard C?

  • qsort()
  • bcmp()
  • memcmp() ANSWER
  • strxfrm()
  • bsearch()

83.

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. ANSWER
  • Variadic functions are discontinued by Standard C; they are legacy constructs from K&R C, and no longer compile under modern compilers.

84.

char *buffer = "0123456789"; 
char *ptr = buffer; 
ptr += 5; 
printf( "%s\n", ptr ); 
printf( "%s\n", buffer );

What will be printed when the sample code above is executed?

0123456789
56789
5123456789
5123456789
56789
56789
0123456789
0123456789
  • ANSWER
56789
0123456789

85.

/* Get the rightmost path element of a Unix path. */
char * get_rightmost (const char * d)
{ 
  char rightmost [MAXPATHLEN]; 
  const char * p = d; 
  assert(d != NULL); 
  while (*d != '\0')
  { 
    if (*d == '/') 
      p = (*(d + 1) != '\0') ? d + 1 : p; 
    d++; 
  } 
  memset(rightmost, 0, sizeof(rightmost)); 
  memcpy(rightmost, p, strlen(p) + 1); 
  return rightmost; 
}

The function get_rightmost(), defined above, contains an error. Which one of the following describes it?

  • The calls to memset() and memcpy() illegally perform a pointer conversion on rightmost without an appropriate cast.
  • The code does not correctly handle the situation where a directory separator '/' is the final character.
  • The if condition contains an incorrectly terminated character literal.
  • memcpy() cannot be used safely to copy string data.
  • The return value of get_rightmost() will be invalid in the caller's context. ANSWER Комментарий

86.

What number is equivalent to -4e3?

  • -4000 ANSWER
  • -400
  • -40
  • .004
  • .0004

87.

void freeList( struct node *n ) 
{ 
  while( n ) 
  { 
    ???? 
  } 
}

Which one of the following can replace the ???? for the function above to release the memory allocated to a linked list?

n = n->next;
free( n );
  • ANSWER
struct node m = n;
n = n->next;
free( m );
struct node m = n;
free( n );
n = m->next;
free( n );
n = n->next;
struct node m = n;
free( m );
n = n->next;

88.

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. ANSWER
  • 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.

89.

int x[] = {1, 2, 3, 4, 5}; 
int u; 
int *ptr = x; 
???? 
for( u = 0; u < 5; u++ )
{
  printf("%d-", x[u]); 
}
printf( "\n" );

Which one of the following statements could replace the ???? in the code above to cause the string 1-2-3-10-5- to be printed when the code is executed?

  • *ptr + 3 = 10;
  • *ptr[ 3 ] = 10;
  • *(ptr + 3) = 10; ANSWER
  • (*ptr)[ 3 ] = 10;
  • *(ptr[ 3 ]) = 10;

90.

/*sum_array() has been ported from FORTRAN. No * logical changes have been made*/
double sum_array(double d[],int n)
{
    register int i;
    double total=0;
    assert(d!=NULL);
    for(i=1; i<=n; i++)
        total+=d[i];
    return total;
}

The function sum_array(), defined above, contains an error. Which one of the following accurately describes it?

  • The loop processes the incorrect number of elements.
  • total is initialized with an integer literal. The two are not compatible in an assignment.
  • The code above fails to compile if there are no registers available for i.
  • The formal parameter d should be declared as double * d to allow dynamically allocated arrays as arguments.
  • The range of the loop does not match the bounds of the array d. ANSWER

91.

#include <stdio.h> 
void func() 
{ 
   int x = 0; 
   static int y = 0; 
   x++; y++; 
   printf( "%d -- %d\n", x, y ); 
} 

int main() 
{ 
   func(); 
   func(); 
   return 0; 
}

What will the code above print when it is executed?

1 -- 1
1 -- 1
1 -- 1
2 -- 1
1 -- 1
2 -- 2
1 -- 0
1 -- 0
  • ANSWER
1 -- 1
1 -- 2

92.

int fibonacci (int n)
{ 
  switch (n)
  { 
    default: 
      return (fibonacci(n - 1) + fibonacci(n - 2)); 
    case 1: 
    case 2: 
  } 
  return 1; 
}

The function above has a flaw that may result in a serious error during some invocations. Which one of the following describes the deficiency illustrated above?

  • For some values of n, the environment will almost certainly exhaust its stack space before the calculation completes. ANSWER Комментарий
  • An error in the algorithm causes unbounded recursion for all values of n.
  • A break statement should be inserted after each case. Fall-through is not desirable here.
  • The fibonacci() function includes calls to itself. This is not directly supported by Standard C due to its unreliability.
  • Since the default case is given first, it will be executed before any case matching n.

93.

When applied to a variable, what does the unary "&" operator yield?

  • The variable's address ANSWER
  • The variable's right value
  • The variable's binary form
  • The variable's value
  • The variable's format

94.

short int x; /* assume x is 16 bits in size */

What is the maximum number that can be printed using printf("%d\n", x), assuming that x is initialized as shown above?

95.

int x = 011 | 0x10;

What value will x contain in the sample code above?

  • 3
  • 13
  • 19
  • 25 ANSWER
  • 27

96.

Which one of the following calls will open the file test.txt for reading by fgetc?

  • fopen( "test.txt", "r" ); ANSWER
  • read( "test.txt" )
  • fileopen( "test.txt", "r" );
  • fread( "test.txt" )
  • freopen( "test.txt" )

97.

int m = -14; 
int n = 6; 
int o; 
o = m % ++n; 
n += m++ - o; 
m <<= (o ^ n) & 3;

Assuming two's-complement arithmetic, which one of the following correctly represents the values of m, n, and o after the execution of the code above?

  • m = -26, n = -7, o = 0 ANSWER
  • m = -52, n = -4, o = -2
  • m = -26, n = -5, o = -2
  • m = -104, n = -7, o = 0
  • m = -52, n = -6, o = 0

98.

How do printf()'s format specifiers %e and %f differ in their treatment of floating-point numbers?

  • %e displays an argument of type double with trailing zeros; %f never displays trailing zeros.
  • %e displays a double in engineering notation if the number is very small or very large. Otherwise, it behaves like %f and displays the number in decimal notation.
  • %e always displays an argument of type double in engineering notation; %f always displays an argument of type double in decimal notation. ANSWER
  • %e expects a corresponding argument of type double; %f expects a corresponding argument of type float.
  • %e and %f both expect a corresponding argument of type double and format it identically. %e is left over from K&R C; Standard C prefers %f for new code.

99.

c = getchar();

What is the proper declaration for the variable c in the code above?

100.

Which one of the following will define a function that CANNOT be called from another source file?

  • void function() { ... }
  • extern void function() { ... }
  • const void function() { ... }
  • private void function() { ... }
  • static void function() { ... } ANSWER


Комментарии

comments powered by Disqus